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

Turn tree-sitter on by default #17879

Merged
merged 11 commits into from
Sep 5, 2018
Prev Previous commit
Next Next commit
Add TreeSitterLanguageMode.tokenForPosition
  • Loading branch information
maxbrunsfeld committed Sep 5, 2018
commit ba96bbf8f193014f060eeabe4253f552a696f1b3
8 changes: 8 additions & 0 deletions spec/tree-sitter-language-mode-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,14 @@ describe('TreeSitterLanguageMode', () => {
'source.js',
'property.name'
])

// Drive-by test for .tokenForPosition()
const token = editor.tokenForBufferPosition([0, 'foo({b'.length])
expect(token.value).toBe('bar')
expect(token.scopes).toEqual([
'source.js',
'property.name'
])
})

it('includes nodes in injected syntax trees', async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {Point, Range, spliceArray} = require('text-buffer')
const {Patch} = require('superstring')
const {Emitter} = require('event-kit')
const ScopeDescriptor = require('./scope-descriptor')
const Token = require('./token')
const TokenizedLine = require('./tokenized-line')
const TextMateLanguageMode = require('./text-mate-language-mode')
const {matcherForSelector} = require('./selectors')
Expand Down Expand Up @@ -435,6 +436,12 @@ class TreeSitterLanguageMode {
return new ScopeDescriptor({scopes})
}

tokenForPosition (point) {
const node = this.getSyntaxNodeAtPosition(point)
const scopes = this.scopeDescriptorForPosition(point).getScopesArray()
return new Token({value: node.text, scopes})
}

getGrammar () {
return this.grammar
}
Expand Down