#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

#186 in Text editors

Download history 522/week @ 2024-09-21 645/week @ 2024-09-28 1004/week @ 2024-10-05 1187/week @ 2024-10-12 957/week @ 2024-10-19 1253/week @ 2024-10-26 835/week @ 2024-11-02 813/week @ 2024-11-09 798/week @ 2024-11-16 806/week @ 2024-11-23 851/week @ 2024-11-30 1034/week @ 2024-12-07 1074/week @ 2024-12-14 728/week @ 2024-12-21 755/week @ 2024-12-28 898/week @ 2025-01-04

3,630 downloads per month
Used in 7 crates (4 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
~121K SLoC