1 unstable release
new 0.1.0 | Jan 20, 2025 |
---|
#2617 in Parser implementations
195KB
4.5K
SLoC
Auto LSP
A Rust crate for creating Abstract Syntax Trees (AST) and Language Server Protocol (LSP) servers powered by Tree-sitter queries
[!IMPORTANT]
auto_lsp
is at an early stage, expect frequent breaking changes.
Quick Example
auto_lsp
is designed to be as language-agnostic as possible, allowing any Tree-sitter grammar to be used.
Defining a simple AST involves two steps: writing the queries and then defining the corresponding AST structures in Rust.
Let's say you have a toy language with a root node named document containing a list of function nodes, each containing a unique name.
A simple query file to capture the root document and function names:
(document) @document
(function
(name) @name) @function
The corresponding AST definition in Rust:
#[seq(query_name = "document", kind(symbol()))]
struct Document {
functions: Vec<Function>
}
#[seq(query_name = "function", kind(symbol()))]
struct Function {
name: Name
}
#[seq(query_name = "name", kind(symbol()))]
struct Name {}
Now that you have your AST defined, you can:
- Implement the LSP traits and create a LSP server (with the
lsp_server
feature). - Add your own logic for testing purposes, code_generation, etc.
You can find more examples in the src/tests
folder.
Features
assertions
: Enable compile-time checks for conflicting queries.deadlock_detection
: Enableparking_lot
's deadlock detection (not compatible withwasm
).log
: Enable logging. (usesstderrlog
)lsp_server
: Enable the LSP server (useslsp_server
).python_test
: Enable the python workspace mock for testing purposes.rayon
: Enablerayon
support (not compatible withwasm
).wasm
: Enable wasm support.
Documentation
The complete documentation will be available in the upcoming book.
Inspirations / Similar projects
- Volar
- Rust-sitter
- StackGraphs
- airblast-dev's texter, which saved hours of headache
Dependencies
~9–21MB
~307K SLoC