mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
Fix #505. Update grammars if any included grammars are updated.
This commit is contained in:
parent
b856ab16cf
commit
35f0b7b49e
@ -242,6 +242,23 @@ describe "TextMateGrammar", ->
|
||||
expect(tokens[21]).toEqual value: 'div', scopes: ["text.html.ruby","meta.tag.block.any.html","entity.name.tag.block.any.html"]
|
||||
expect(tokens[22]).toEqual value: '>', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.end.html"]
|
||||
|
||||
it "updates the grammar if the included grammar is updated later", ->
|
||||
atom.activatePackage('html.tmbundle', sync: true)
|
||||
atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
|
||||
|
||||
grammar = syntax.selectGrammar('foo.html.erb')
|
||||
grammarUpdatedHandler = jasmine.createSpy("grammarUpdatedHandler")
|
||||
grammar.on 'grammar-updated', grammarUpdatedHandler
|
||||
|
||||
{tokens} = grammar.tokenizeLine("<div class='name'><% <<-SQL select * from users;")
|
||||
expect(tokens[12].value).toBe " select * from users;"
|
||||
|
||||
atom.activatePackage('sql.tmbundle', sync: true)
|
||||
expect(grammarUpdatedHandler).toHaveBeenCalled()
|
||||
{tokens} = grammar.tokenizeLine("<div class='name'><% <<-SQL select * from users;")
|
||||
expect(tokens[12].value).toBe " "
|
||||
expect(tokens[13].value).toBe "select"
|
||||
|
||||
describe "when a grammar matching the desired scope is unavailable", ->
|
||||
it "updates the grammar if a matching grammar is added later", ->
|
||||
atom.deactivatePackage('html.tmbundle')
|
||||
|
@ -15,6 +15,6 @@ class NullGrammar
|
||||
tokenizeLine: (line) ->
|
||||
{ tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] }
|
||||
|
||||
grammarAddedOrRemoved: -> # no op
|
||||
grammarUpdated: -> # noop
|
||||
|
||||
_.extend NullGrammar.prototype, EventEmitter
|
||||
|
@ -34,16 +34,17 @@ class Syntax
|
||||
previousGrammars = new Array(@grammars...)
|
||||
@grammars.push(grammar)
|
||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||
@notifyOtherGrammars(previousGrammars, grammar.scopeName)
|
||||
@grammarUpdated(grammar.scopeName)
|
||||
@trigger 'grammar-added', grammar
|
||||
|
||||
removeGrammar: (grammar) ->
|
||||
_.remove(@grammars, grammar)
|
||||
delete @grammarsByScopeName[grammar.scopeName]
|
||||
@notifyOtherGrammars(@grammars, grammar.scopeName)
|
||||
@grammarUpdated(grammar.scopeName)
|
||||
|
||||
notifyOtherGrammars: (grammars, scopeName) ->
|
||||
grammar.grammarAddedOrRemoved(scopeName) for grammar in grammars
|
||||
grammarUpdated: (scopeName) ->
|
||||
for grammar in @grammars when grammar.scopeName isnt scopeName
|
||||
grammar.grammarUpdated(scopeName)
|
||||
|
||||
setGrammarOverrideForPath: (path, scopeName) ->
|
||||
@grammarOverridesByPath[path] = scopeName
|
||||
|
@ -64,9 +64,10 @@ class TextMateGrammar
|
||||
addIncludedGrammarScope: (scope) ->
|
||||
@includedGrammarScopes.push(scope) unless _.include(@includedGrammarScopes, scope)
|
||||
|
||||
grammarAddedOrRemoved: (scopeName) =>
|
||||
grammarUpdated: (scopeName) =>
|
||||
return unless _.include(@includedGrammarScopes, scopeName)
|
||||
@clearRules()
|
||||
syntax.grammarUpdated(@scopeName)
|
||||
@trigger 'grammar-updated'
|
||||
|
||||
getScore: (path, contents) ->
|
||||
|
Loading…
Reference in New Issue
Block a user