#tree-sitter #ast #powered #auto #html #language-server-protocol

auto-lsp

A rust crate for creating AST and LSP servers powered by tree-sitter queries

4 releases (2 breaking)

0.5.1 Mar 15, 2025
0.5.0 Mar 14, 2025
0.4.0 Mar 3, 2025
0.3.0 Feb 14, 2025
0.1.0 Jan 20, 2025

#2344 in Parser implementations

Download history 93/week @ 2025-01-15 135/week @ 2025-01-22 17/week @ 2025-01-29 23/week @ 2025-02-05 126/week @ 2025-02-12 17/week @ 2025-02-19 153/week @ 2025-02-26 39/week @ 2025-03-05 253/week @ 2025-03-12

469 downloads per month

MIT license

3MB
10K SLoC

Rust 8K SLoC // 0.0% comments JavaScript 2K SLoC // 0.0% comments Shell 4 SLoC

Auto LSP

A Rust crate for creating Abstract Syntax Trees (AST) and Language Server Protocol (LSP) servers powered by Tree-sitter queries

CI Status CI Status Book crates.io Rust Version

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 = "document")]
struct Document {
   functions: Vec<Function>
}

#[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 and create a LSP server (with the lsp_server feature).
  • Add your own logic for testing purposes, code generation, etc.

Documentation

Examples

Features

  • deadlock_detection: Enable parking_lot's deadlock detection (not compatible with wasm).
  • log: Enable logging. (uses stderrlog)
  • lsp_server: Enable the LSP server (uses lsp_server).
  • rayon: Enable rayon support (only compatible with wasi-p1-threads).
  • wasm: Enable wasm support.
  • html: Enable the html workspace mock for testing purposes.
  • python: Enable the python workspace mock for testing purposes.

Inspirations / Similar projects

Dependencies

~9–21MB
~304K SLoC