GrammarRegistry
Description
Registry containing one or more grammars.
API documentation
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.
Managing Grammars
::getGrammars()
Get all the grammars in this registry.
Return values
::grammarForScopeName(scopeName)
Get a grammar with the given scope name.
| Argument | Description |
|---|---|
scopeName
|
A String such as |
Return values
-
Returns a Grammar or .
::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 GrammarRegistry::readGrammar or GrammarRegistry::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 |
Return values
-
Returns the removed Grammar or .
::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 .
::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 .
::grammarOverrideForPath(filePath)
Get the grammar override for the given file path.
| Argument | Description |
|---|---|
filePath
|
A String file path. |
Return values
-
Returns a Grammar or .
::setGrammarOverrideForPath(filePath, scopeName)
Set the grammar override for the given file path.
| Argument | Description |
|---|---|
filePath
|
A non-empty String file path. |
scopeName
|
A String such as |
Return values
-
Returns a Grammar or .
::clearGrammarOverrideForPath(filePath)
Remove the grammar override for the given file path.
| Argument | Description |
|---|---|
filePath
|
A String file path. |
Return values
-
Returns .
::clearGrammarOverrides()
Remove all grammar overrides.
Return values
-
Returns .
::selectGrammar(filePath, fileContents)
Select a grammar for the given file path and file contents.
This picks the best match by checking the file path and contents against each grammar.
| Argument | Description |
|---|---|
filePath
|
A String file path. |
fileContents
|
A String of text for the file path. |
Return values
-
Returns a Grammar, never null.