Re-wiring things so language-mode considers new grammar

This commit is contained in:
Maurício Szabo 2023-02-22 01:23:02 -03:00
parent 11c8e093eb
commit 843700e17e
2 changed files with 6 additions and 12 deletions

View File

@ -32,10 +32,6 @@ describe('WASM Tree-sitter Ruby grammar', () => {
allMatches.forEach(({text, row, col}) => {
const exactPos = text.match(/\^\s+(.*)/)
if(exactPos) {
console.log(
'Scopes:',
editor.scopeDescriptorForBufferPosition([row, exactPos.index]).toString()
)
expect(editor.scopeDescriptorForBufferPosition([row, exactPos.index]).scopes).toSatisfy((scopes, reason) => {
const expected = exactPos[1]
reason(dedent`

View File

@ -9,7 +9,7 @@ createTree = require("./rb-tree")
const VAR_ID = 257
class WASMTreeSitterLanguageMode {
constructor( buffer, config) {
constructor(buffer, config, grammar) {
this.emitter = new Emitter();
this.lastId = 259
this.scopeNames = new Map([["variable", VAR_ID]])
@ -23,14 +23,12 @@ class WASMTreeSitterLanguageMode {
this.ready = new Promise(r => resolve = r)
initPromise.then(() =>
Parser.Language.load('/tmp/grammars/ruby/grammar.wasm')
Parser.Language.load(grammar.grammarPath)
).then(lang => {
const syntaxQuery = fs.readFileSync('/tmp/grammars/ruby/queries/highlights.scm', 'utf-8')
if(fs.existsSync('/tmp/grammars/ruby/queries/locals.scm')) {
const localsQuery = fs.readFileSync('/tmp/grammars/ruby/queries/locals.scm', 'utf-8')
this.localsQuery = lang.query(localsQuery)
this.syntaxQuery = lang.query(grammar.syntaxQuery)
if(grammar.localsQuery) {
this.localsQuery = lang.query(grammar.localsQuery)
}
this.syntaxQuery = lang.query(syntaxQuery)
this.parser = new Parser()
this.parser.setLanguage(lang)
@ -45,7 +43,7 @@ class WASMTreeSitterLanguageMode {
})
this.rootScopeDescriptor = new ScopeDescriptor({
scopes: ['ruby']
scopes: [grammar.scopeName]
});
}