mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Always include root scope name in Tree-sitter scope descriptors
This commit is contained in:
@@ -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)', () => {
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user