GrammarRegistry Extended

Registry containing one or more grammars.

Event Subscription

::onDidAddGrammar(callback)

Invoke the given callback when a grammar is added to the registry.

Argument Description

callback

Function to call when a grammar is added.

grammar

Grammar that was added.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidUpdateGrammar(callback)

Invoke the given callback when a grammar is updated due to a grammar it depends on being added or removed from the registry.

Argument Description

callback

Function to call when a grammar is updated.

grammar

Grammar that was updated.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidRemoveGrammar(callback)

Invoke the given callback when a grammar is removed from the registry.

Argument Description

callback

Function to call when a grammar is removed.

grammar

Grammar that was removed.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

Managing Grammars

::getGrammars()

Get all the grammars in this registry.

Return values

Returns a non-empty Array of Grammar instances.

::grammarForScopeName(scopeName)

Get a grammar with the given scope name.

Argument Description

scopeName

A String such as "source.js".

Return values

Returns a Grammar or undefined.

::addGrammar(grammar)

Add a grammar to this registry.

A ‘grammar-added’ event is emitted after the grammar is added.

Argument Description

grammar

The Grammar to add. This should be a value previously returned from ::readGrammar or ::readGrammarSync.

Return values

Returns a Disposable on which .dispose() can be called to remove the grammar.

::removeGrammarForScopeName(scopeName)

Remove the grammar with the given scope name.

Argument Description

scopeName

A String such as "source.js".

Return values

Returns the removed Grammar or undefined.

::readGrammarSync(grammarPath)

Read a grammar synchronously but don’t add it to the registry.

Argument Description

grammarPath

A String absolute file path to a grammar file.

Return values

Returns a Grammar.

::readGrammar(grammarPath, callback)

Read a grammar asynchronously but don’t add it to the registry.

Argument Description

grammarPath

A String absolute file path to a grammar file.

callback

A Function to call when read with the following arguments:

error

An Error, may be null.

grammar

A Grammar or null if an error occured.

Return values

Returns undefined.

::loadGrammarSync(grammarPath)

Read a grammar synchronously and add it to this registry.

Argument Description

grammarPath

A String absolute file path to a grammar file.

Return values

Returns a Grammar.

::loadGrammar(grammarPath, callback)

Read a grammar asynchronously and add it to the registry.

Argument Description

grammarPath

A String absolute file path to a grammar file.

callback

A Function to call when loaded with the following arguments:

error

An Error, may be null.

grammar

A Grammar or null if an error occured.

Return values

Returns undefined.