• Stars
    star
    973
  • Rank 47,051 (Top 1.0 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Language Server Protocol implementation written in Rust

tower-lsp

Build Status Crates.io Documentation

Language Server Protocol implementation for Rust based on Tower.

Tower is a simple and composable framework for implementing asynchronous services in Rust. Central to Tower is the Service trait, which provides the necessary abstractions for defining request/response clients and servers. Examples of protocols implemented using the Service trait include hyper for HTTP and tonic for gRPC.

This library (tower-lsp) provides a simple implementation of the Language Server Protocol (LSP) that makes it easy to write your own language server. It consists of three parts:

  • The LanguageServer trait which defines the behavior of your language server.
  • The asynchronous LspService delegate which wraps your language server implementation and defines the behavior of the protocol.
  • A Server which spawns the LspService and processes requests and responses over stdio or TCP.

Example

use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};

#[derive(Debug)]
struct Backend {
    client: Client,
}

#[tower_lsp::async_trait]
impl LanguageServer for Backend {
    async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> {
        Ok(InitializeResult::default())
    }

    async fn initialized(&self, _: InitializedParams) {
        self.client
            .log_message(MessageType::INFO, "server initialized!")
            .await;
    }

    async fn shutdown(&self) -> Result<()> {
        Ok(())
    }
}

#[tokio::main]
async fn main() {
    let stdin = tokio::io::stdin();
    let stdout = tokio::io::stdout();

    let (service, socket) = LspService::new(|client| Backend { client });
    Server::new(stdin, stdout, socket).serve(service).await;
}

Using runtimes other than tokio

By default, tower-lsp is configured for use with tokio.

Using tower-lsp with other runtimes requires disabling default-features and enabling the runtime-agnostic feature:

[dependencies.tower-lsp]
version = "*"
default-features = false
features = ["runtime-agnostic"]

Using proposed features

You can use enable proposed features in the LSP Specification version 3.17 by enabling the proposed Cargo crate feature. Note that there are no semver guarantees to the proposed features so there may be breaking changes between any type of version in the proposed features.

Ecosystem

  • tower-lsp-boilerplate - Useful GitHub project template which makes writing new language servers easier.

License

tower-lsp is free and open source software distributed under the terms of either the MIT or the Apache 2.0 license, at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

renderdoc-rs

RenderDoc application bindings for Rust
Rust
44
star
2

nix-language-server

Language server for the Nix language (WIP)
Rust
40
star
3

libnar

NAR (Nix Archive) reader/writer implementation written in Rust
Rust
37
star
4

example-fault-tolerant-parser

Fault-tolerant nom 5 parser based on "Syntax error recovery in parsing expression grammars" (2018)
Rust
28
star
5

ray-tracing-in-one-weekend

Rust implementation of the book "Ray Tracing in One Weekend" by Peter Shirley
Rust
12
star
6

dotfiles

Tiny platform-agnostic package manager for my personal dotfiles
Shell
8
star
7

bastille

Process sandboxing library written in Rust
Rust
7
star
8

experimental-repo

Prototypes and daemons abound...
C#
6
star
9

merkle-tree-nix-store-thing

Basic implementation of a Nix-like store abstraction over a Merkle tree
Rust
6
star
10

cs143-compilers

Compiler for the Classroom Object-Oriented Language (Stanford CS143, 2021)
Java
5
star
11

tq

Command-line TOML processor
Rust
3
star
12

ebkalderon.github.io

Personal website and portfolio
TeX
3
star
13

deck

Declarative package manager experiment
Rust
2
star
14

rust-toronto-gamedev-2017

Slides from Amethyst talk given at Mozilla Toronto
2
star
15

gtksourceview-squirrel

Squirrel syntax highlighting for GtkSourceView
2
star
16

freedesktop-categories

Static hash map of all Freedesktop.org categories in Rust
Rust
1
star
17

freedesktop-entry

Parser for the Freedesktop Desktop Entry specification written in Rust
Rust
1
star
18

appstream

Parser for AppStream data written in Rust
Rust
1
star
19

ukama-coding-assignment

Lightweight container engine with REST API
Rust
1
star
20

dss-coding-assignment

Interactive media navigation menu populated by JSON API
Rust
1
star
21

tmachine

The plot of H.G. Well's The Time Machine represented in code (English 12 HN final project)
C++
1
star