Move grammar override logic into TextEditorRegistry

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Max Brunsfeld
2016-07-26 15:00:20 -07:00
committed by Nathan Sobo
parent 455d3213ed
commit a44d5833a8
3 changed files with 62 additions and 35 deletions

View File

@@ -85,6 +85,27 @@ describe('TextEditorRegistry', function () {
})
})
describe('.setGrammarOverride and .clearGrammarOverride', function () {
it('sets the editor\'s grammar and does not update it based on other criteria until the override is cleared', async function () {
registry.maintainGrammar(editor)
await atom.packages.activatePackage('language-c')
expect(editor.getGrammar().name).toBe('Null Grammar')
registry.setGrammarOverride(editor, atom.grammars.grammarForScopeName('source.c'))
expect(editor.getGrammar().name).toBe('C')
editor.getBuffer().setPath('file-1.js')
await atom.packages.activatePackage('language-javascript')
expect(editor.getGrammar().name).toBe('C')
editor.getBuffer().setPath('file-2.js')
expect(editor.getGrammar().name).toBe('C')
registry.clearGrammarOverride(editor)
expect(editor.getGrammar().name).toBe('JavaScript')
})
})
describe('.maintainConfig(editor)', function () {
it('does not update editors when config settings change for unrelated scope selectors', async function () {
await atom.packages.activatePackage('language-javascript')

View File

@@ -5225,24 +5225,8 @@ describe "TextEditor", ->
editor.setIndentationForBufferRow(0, 2.1)
expect(editor.getText()).toBe(" 1\n\t2")
describe ".reloadGrammar()", ->
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage('language-coffee-script')
it "updates the grammar based on grammar overrides", ->
expect(editor.getGrammar().name).toBe 'JavaScript'
atom.grammars.setGrammarOverrideForPath(editor.getPath(), 'source.coffee')
callback = jasmine.createSpy('callback')
editor.onDidChangeGrammar(callback)
editor.reloadGrammar()
expect(editor.getGrammar().name).toBe 'CoffeeScript'
expect(callback.callCount).toBe 1
expect(callback.argsForCall[0][0]).toBe atom.grammars.grammarForScopeName('source.coffee')
describe "when the editor's grammar has an injection selector", ->
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage('language-text')