Merge pull request #16814 from atom/mb-default-scope-descriptor

Provide a default scope descriptor if language mode doesn't provide them
This commit is contained in:
Max Brunsfeld 2018-02-21 16:06:56 -08:00 committed by GitHub
commit 983406e166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -6747,6 +6747,14 @@ describe('TextEditor', () => {
editor.destroy()
})
describe('.scopeDescriptorForBufferPosition(position)', () => {
it('returns a default scope descriptor when no language mode is assigned', () => {
editor = new TextEditor({buffer: new TextBuffer()})
const scopeDescriptor = editor.scopeDescriptorForBufferPosition([0, 0])
expect(scopeDescriptor.getScopesArray()).toEqual(['text'])
})
})
describe('.shouldPromptToSave()', () => {
beforeEach(async () => {
editor = await atom.workspace.open('sample.js')

View File

@ -11,6 +11,7 @@ const Cursor = require('./cursor')
const Selection = require('./selection')
const NullGrammar = require('./null-grammar')
const TextMateLanguageMode = require('./text-mate-language-mode')
const ScopeDescriptor = require('./scope-descriptor')
const TextMateScopeSelector = require('first-mate').ScopeSelector
const GutterContainer = require('./gutter-container')
@ -3655,7 +3656,10 @@ class TextEditor {
//
// Returns a {ScopeDescriptor}.
scopeDescriptorForBufferPosition (bufferPosition) {
return this.buffer.getLanguageMode().scopeDescriptorForPosition(bufferPosition)
const languageMode = this.buffer.getLanguageMode()
return languageMode.scopeDescriptorForPosition
? languageMode.scopeDescriptorForPosition(bufferPosition)
: new ScopeDescriptor({scopes: ['text']})
}
// Extended: Get the range in buffer coordinates of all tokens surrounding the