From 843700e17eef6431719b8ad5656f396edb9ea4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Szabo?= Date: Wed, 22 Feb 2023 01:23:02 -0300 Subject: [PATCH] Re-wiring things so language-mode considers new grammar --- .../language-ruby/spec/wasm-tree-sitter-spec.js | 4 ---- src/wasm-tree-sitter-language-mode.js | 14 ++++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/language-ruby/spec/wasm-tree-sitter-spec.js b/packages/language-ruby/spec/wasm-tree-sitter-spec.js index e96d8532a..ed6075d39 100644 --- a/packages/language-ruby/spec/wasm-tree-sitter-spec.js +++ b/packages/language-ruby/spec/wasm-tree-sitter-spec.js @@ -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` diff --git a/src/wasm-tree-sitter-language-mode.js b/src/wasm-tree-sitter-language-mode.js index 5b4bc85aa..f16c583cb 100644 --- a/src/wasm-tree-sitter-language-mode.js +++ b/src/wasm-tree-sitter-language-mode.js @@ -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] }); }