Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental parsing #21

Closed
AnHeuermann opened this issue Apr 4, 2024 · 0 comments · Fixed by #25
Closed

Incremental parsing #21

AnHeuermann opened this issue Apr 4, 2024 · 0 comments · Fixed by #25
Labels
LS - Server Language Server - Server capability

Comments

@AnHeuermann
Copy link
Member

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:

const tree = this.parser.parse(fileContent);

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)

@AnHeuermann AnHeuermann added the LS - Server Language Server - Server capability label Apr 4, 2024
@AnHeuermann AnHeuermann linked a pull request May 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LS - Server Language Server - Server capability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant