https://github.com/adclz/auto-lsp
A rust crate for creating AST and LSP servers powered by tree-sitter queries.
https://github.com/adclz/auto-lsp
parsing rust tree-sitter wasm
Last synced: about 2 months ago
JSON representation
A rust crate for creating AST and LSP servers powered by tree-sitter queries.
- Host: GitHub
- URL: https://github.com/adclz/auto-lsp
- Owner: adclz
- License: gpl-3.0
- Created: 2024-10-28T13:41:20.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-04-29T17:09:14.000Z (about 2 months ago)
- Last Synced: 2025-04-30T05:45:42.676Z (about 2 months ago)
- Topics: parsing, rust, tree-sitter, wasm
- Language: Rust
- Homepage: https://adclz.github.io/auto-lsp/
- Size: 2.76 MB
- Stars: 23
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.md
- License: LICENSE.TXT
Awesome Lists containing this project
README
Auto LSP
A Rust crate for creating Abstract Syntax Trees (AST)
and Language Server Protocol (LSP) servers powered by Tree-sitter queries
[](https://github.com/adclz/auto-lsp/actions/workflows/ast-gen-native.yml)
[](https://github.com/adclz/auto-lsp/actions/workflows/lsp-server-native.yml)
[](https://adclz.github.io/auto-lsp/)
[](https://crates.io/crates/auto-lsp)
> `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:
```lisp
(document) @document
(function
(name) @name) @function
```The corresponding AST definition in Rust:
```rust
#[seq(query = "document")]
struct Document {
functions: Vec
}#[seq(query = "function")]
struct Function {
name: Name
}#[seq(query = "name")]
struct Name {}
```Now that you have your AST defined, you can:
- Implement the [AST traits](https://adclz.github.io/auto-lsp/ast-and-queries/seq.html#seq-attributes) and create a LSP server (with the `lsp_server` feature).
- Add your own logic for testing purposes, code generation, etc.# Documentation
- [book](https://adclz.github.io/auto-lsp/)
- [docs.rs](https://docs.rs/auto-lsp)## Examples
- [HTML Ast](https://github.com/adclz/auto-lsp/blob/main/src/tests/html_workspace/mod.rs)
- [Python Ast](https://github.com/adclz/auto-lsp/blob/main/src/tests/python_workspace/ast.rs)
- [Simple LSP Server](https://github.com/adclz/auto-lsp/tree/main/examples/native)
- [Vscode extension with WASI](https://github.com/adclz/auto-lsp/tree/main/examples/vscode-wasi)# Features
- `lsp_server`: Enable the LSP server (uses [`lsp_server`](https://crates.io/crates/lsp-server)).
- `wasm`: Enable wasm support (only compatible with `wasi-p1-threads`).
- `html`: Enable the html workspace mock for testing purposes.
- `python`: Enable the python workspace mock for testing purposes.# Inspirations / Similar projects
- [Volar](https://volarjs.dev/)
- [Rust-sitter](https://github.com/hydro-project/rust-sitter)
- [StackGraphs](https://github.com/github/stack-graphs)
- [airblast-dev](https://github.com/airblast-dev)'s [texter](https://github.com/airblast-dev/texter), which saved hours of headache