mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Make scopeDescriptorForPosition work correctly between tokens
Fixes atom/bracket-matcher#365
This commit is contained in:
@@ -1517,6 +1517,27 @@ describe('TreeSitterLanguageMode', () => {
|
||||
'source.js'
|
||||
])
|
||||
})
|
||||
|
||||
it('works when the given position is between tokens', () => {
|
||||
const grammar = new TreeSitterGrammar(atom.grammars, jsGrammarPath, {
|
||||
scopeName: 'source.js',
|
||||
parser: 'tree-sitter-javascript',
|
||||
scopes: {
|
||||
program: 'source.js',
|
||||
comment: 'comment.block',
|
||||
}
|
||||
})
|
||||
|
||||
buffer.setText('a // b')
|
||||
buffer.setLanguageMode(new TreeSitterLanguageMode({buffer, grammar}))
|
||||
expect(editor.scopeDescriptorForBufferPosition([0, 2]).getScopesArray()).toEqual([
|
||||
'source.js'
|
||||
])
|
||||
expect(editor.scopeDescriptorForBufferPosition([0, 3]).getScopesArray()).toEqual([
|
||||
'source.js',
|
||||
'comment.block'
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('.syntaxTreeScopeDescriptorForPosition', () => {
|
||||
|
||||
@@ -479,13 +479,16 @@ class TreeSitterLanguageMode {
|
||||
}
|
||||
|
||||
scopeDescriptorForPosition (point) {
|
||||
point = Point.fromObject(point)
|
||||
const iterator = this.buildHighlightIterator()
|
||||
const scopes = []
|
||||
for (const scope of iterator.seek(point)) {
|
||||
scopes.push(this.grammar.scopeNameForScopeId(scope))
|
||||
}
|
||||
for (const scope of iterator.getOpenScopeIds()) {
|
||||
scopes.push(this.grammar.scopeNameForScopeId(scope))
|
||||
if (point.isEqual(iterator.getPosition())) {
|
||||
for (const scope of iterator.getOpenScopeIds()) {
|
||||
scopes.push(this.grammar.scopeNameForScopeId(scope))
|
||||
}
|
||||
}
|
||||
if (scopes.length === 0 || scopes[0] !== this.grammar.scopeName) {
|
||||
scopes.unshift(this.grammar.scopeName)
|
||||
|
||||
Reference in New Issue
Block a user