Skip to content
/ auto-lsp Public

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

License

Notifications You must be signed in to change notification settings

adclz/auto-lsp

Folders and files

NameName
Last commit message
Last commit date
Feb 14, 2025
Jan 14, 2025
Mar 2, 2025
Mar 3, 2025
Mar 3, 2025
Mar 1, 2025
Mar 3, 2025
Mar 3, 2025
Jan 8, 2025
Mar 3, 2025
Mar 3, 2025
Jan 10, 2025
Mar 1, 2025
Mar 2, 2025
Feb 2, 2025

Repository files navigation

Auto LSP

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

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 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

  • 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 (not compatible with wasm).
  • wasm: Enable wasm support.
  • html: Enable the html workspace mock for testing purposes.
  • python: Enable the python workspace mock for testing purposes.

Documentation

Inspirations / Similar projects