- Notifications
You must be signed in to change notification settings - Fork66
Language Server Protocol implementation written in Rust
License
Apache-2.0, MIT licenses found
Licenses found
ebkalderon/tower-lsp
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Language Server Protocol implementation for Rust based onTower.
Tower is a simple and composable framework for implementing asynchronousservices in Rust. Central to Tower is theService
trait, which provides thenecessary abstractions for defining request/response clients and servers.Examples of protocols implemented using theService
trait includehyper
for HTTP andtonic
for gRPC.
This library (tower-lsp
) provides a simple implementation of the LanguageServer Protocol (LSP) that makes it easy to write your own language server. Itconsists of three parts:
- The
LanguageServer
trait which defines the behavior of your language server. - The asynchronous
LspService
delegate which wraps your language serverimplementation and defines the behavior of the protocol. - A
Server
which spawns theLspService
and processes requests and responsesoverstdio
or TCP.
use tower_lsp::jsonrpc::Result;use tower_lsp::lsp_types::*;use tower_lsp::{Client,LanguageServer,LspService,Server};#[derive(Debug)]structBackend{client:Client,}#[tower_lsp::async_trait]implLanguageServerforBackend{asyncfninitialize(&self, _:InitializeParams) ->Result<InitializeResult>{Ok(InitializeResult::default())}asyncfninitialized(&self, _:InitializedParams){self.client.log_message(MessageType::INFO,"server initialized!").await;}asyncfnshutdown(&self) ->Result<()>{Ok(())}}#[tokio::main]asyncfnmain(){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;}
By default,tower-lsp
is configured for use withtokio
.
Usingtower-lsp
with other runtimes requires disablingdefault-features
andenabling theruntime-agnostic
feature:
[dependencies.tower-lsp]version ="*"default-features =falsefeatures = ["runtime-agnostic"]
You can use enable proposed features in theLSP Specification version 3.18by enabling theproposed
Cargo crate feature. Note that there are no semverguarantees to theproposed
features so there may be breaking changes betweenany type of version in theproposed
features.
- tower-lsp-boilerplate - Useful GitHub project template which makes writing new language servers easier.
tower-lsp
is free and open source software distributed under the terms ofeither theMIT or theApache 2.0 license, atyour option.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall bedual licensed as above, without any additional terms or conditions.
About
Language Server Protocol implementation written in Rust