Closed AnHeuermann closed 5 months ago
Tree-sitter can use incremental parsing to speedup the re-parsing of files, see https://tree-sitter.github.io/tree-sitter/using-parsers#editing.
Currently modelica-language-server always parses the whole file on every change: https://github.com/OpenModelica/modelica-language-server/blob/a52ced7a3cdb3d050106f5edb9323e7c4797199a/server/src/analyzer.ts#L73
To incrementally parse a file the language server needs to track changes from the client. So all changed locations need to be added to the tree:
// first parsing const sourceCode = 'let x = 1; console.log(x);'; const tree = parser.parse(sourceCode); // Replace 'let' with 'const' const newSourceCode = 'const x = 1; console.log(x);'; tree.edit({ startIndex: 0, oldEndIndex: 3, newEndIndex: 5, startPosition: {row: 0, column: 0}, oldEndPosition: {row: 0, column: 3}, newEndPosition: {row: 0, column: 5}, }); const newTree = parser.parse(newSourceCode, tree);
(from https://github.com/tree-sitter/tree-sitter/blob/master/lib/binding_web/README.md#editing)
Tree-sitter can use incremental parsing to speedup the re-parsing of files, see https://tree-sitter.github.io/tree-sitter/using-parsers#editing.
Currently modelica-language-server always parses the whole file on every change: https://github.com/OpenModelica/modelica-language-server/blob/a52ced7a3cdb3d050106f5edb9323e7c4797199a/server/src/analyzer.ts#L73
To incrementally parse a file the language server needs to track changes from the client. So all changed locations need to be added to the tree:
(from https://github.com/tree-sitter/tree-sitter/blob/master/lib/binding_web/README.md#editing)