Skip to content

Conversation

@gerau
Copy link
Contributor

@gerau gerau commented Nov 27, 2025

This integrates tree-sitter grammar parser in order to implement more features for LSP. The following features have now been added:

  • completion for variables
  • hover for variables and built-in types
  • references for variables and type aliases

also fixes issue with reference and hover for functions inside generics type (for_while, fold and array_fold).

Previously, navigation was based on constructs built from the original compiler parser, but it removes a lot of important information needed for this, such as the location of some tokens.

Tree-sitter allows us to track token positions, make queries to find individual elements, perform quick searches by position, and perform incremental parsing.

We could also use the original grammar for pest parser, using the existing grammar file inside the compiler, but that would require rewriting the parsing logic from scratch. Also, tree-sitter is more convenient to use for LSP features.

Add the tree-sitter grammar parser and use it for the main LSP functions.

Functions changed:
- completion: completion now also accepts visible variables for
  completion, which we obtain with tree-sitter.
- hover: now it searches inside the tree-sitter AST instead of the AST
  generated by the SimplicityHL compiler. Also added more hover options,
  such as types and variables.
- goto-definition and references: also updated to search using the tree-sitter
  AST and to use tree-sitter’s query features for finding definitions and
  references.

As we now use the AST provided by tree-sitter, the functions working with
the compiler AST are removed, as is the `miniscript` crate.

Added the `documentation` module, because all SimplicityHL function
documentation was previously inside the `completion` module, which was
confusing since this documentation is also used by other functions,
such as `hover`.
@KyrylR
Copy link
Collaborator

KyrylR commented Dec 2, 2025

This change introduces a bigger maintenance scope than I had expected

I would like to reiterate with the team to understand what we can do to improve the language instead of trying to introduce more parsers

With this addition, we will have 4 different grammars (pest, nom, vscode, tree-sitter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants