Skip to content

latex-lsp/language-server

Repository files navigation

CI Coverage Rust LSP Dependabot crates.io docs.rs

language-server

A library to implement asynchronous language servers in Rust. It features

  • Full server and client support of the Language Server Protocol 3.15.
  • Independent of the underlying transport layer and the used async executor.

Example

A simple language server using the Tokio runtime:

use async_executors::TokioTp;
use language_server::{async_trait::async_trait, types::*, *};
use std::{convert::TryFrom, sync::Arc};
use tokio_util::compat::*;

struct Server;

#[async_trait]
impl LanguageServer for Server {
    async fn initialize(
        &self,
        _params: InitializeParams,
        _client: Arc<dyn LanguageClient>,
    ) -> Result<InitializeResult> {
        Ok(InitializeResult::default())
    }

    async fn initialized(&self, _params: InitializedParams, client: Arc<dyn LanguageClient>) {
        let params = ShowMessageParams {
            typ: MessageType::Info,
            message: "Hello World!".to_owned(),
        };

        client.show_message(params).await;
    }
}

fn main() {
    let executor = TokioTp::try_from(&mut tokio::runtime::Builder::new())
        .expect("failed to create thread pool");

    executor.block_on(
        LanguageService::builder()
            .server(Arc::new(Server))
            .input(tokio::io::stdin().compat())
            .output(tokio::io::stdout().compat_write())
            .executor(executor.clone())
            .build()
            .listen(),
    );
}

More examples can be found here.

About

A library to implement language servers in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages