Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Always include root scope name in Tree-sitter scope descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Aug 28, 2018
1 parent fb7e852 commit 85ce0aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/tree-sitter-language-mode-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}

Expand Down

0 comments on commit 85ce0aa

Please sign in to comment.