#client-server #language-server-protocol #lsp #deno #tower #protocols #io

deno_tower_lsp

This is a fork of https://crates.io/crates/tower-lsp, used in Deno. At the moment only floating patches.

1 unstable release

0.1.0 Aug 23, 2024

#79 in Text editors

Download history 57/week @ 2024-08-17 625/week @ 2024-08-24 670/week @ 2024-08-31 857/week @ 2024-09-07 457/week @ 2024-09-14 522/week @ 2024-09-21 645/week @ 2024-09-28 1004/week @ 2024-10-05 1187/week @ 2024-10-12 965/week @ 2024-10-19 1270/week @ 2024-10-26

4,538 downloads per month
Used in 5 crates (2 directly)

MIT license

210KB
3K SLoC

This is a fork of https://crates.io/crates/tower-lsp, used in Deno. At the moment only floating patches.


lib.rs:

Language Server Protocol (LSP) server abstraction for Tower.

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 {
            capabilities: ServerCapabilities {
                hover_provider: Some(HoverProviderCapability::Simple(true)),
                completion_provider: Some(CompletionOptions::default()),
                ..Default::default()
            },
            ..Default::default()
        })
    }

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

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

    async fn completion(&self, _: CompletionParams) -> Result<Option<CompletionResponse>> {
        Ok(Some(CompletionResponse::Array(vec![
            CompletionItem::new_simple("Hello".to_string(), "Some detail".to_string()),
            CompletionItem::new_simple("Bye".to_string(), "More detail".to_string())
        ])))
    }

    async fn hover(&self, _: HoverParams) -> Result<Option<Hover>> {
        Ok(Some(Hover {
            contents: HoverContents::Scalar(
                MarkedString::String("You're hovering!".to_string())
            ),
            range: None
        }))
    }
}

#[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;
}

Dependencies

~4–11MB
~123K SLoC