Always include root scope name in Tree-sitter scope descriptors

This commit is contained in:
Max Brunsfeld
2018-08-27 17:03:20 -07:00
parent 6456f8a032
commit 3160c60c00
2 changed files with 20 additions and 0 deletions

View File

@@ -1413,6 +1413,23 @@ describe('TreeSitterLanguageMode', () => {
'property.name'
])
})
it('includes the root scope name even when the given position is in trailing whitespace at EOF', () => {
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
scopeName: 'source.js',
parser: 'tree-sitter-javascript',
scopes: {
program: 'source.js',
property_identifier: 'property.name'
}
})
buffer.setText('a; ')
buffer.setLanguageMode(new TreeSitterLanguageMode({buffer, grammar}))
expect(editor.scopeDescriptorForBufferPosition([0, 3]).getScopesArray()).toEqual([
'source.js'
])
})
})
describe('.bufferRangeForScopeAtPosition(selector?, position)', () => {

View File

@@ -429,6 +429,9 @@ class TreeSitterLanguageMode {
for (const scope of iterator.getOpenScopeIds()) {
scopes.push(this.grammar.scopeNameForScopeId(scope, false))
}
if (scopes.length === 0 || scopes[0] !== this.grammar.scopeName) {
scopes.unshift(this.grammar.scopeName)
}
return new ScopeDescriptor({scopes})
}