#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

#217 in Text editors

Download history 510/week @ 2024-08-25 682/week @ 2024-09-01 856/week @ 2024-09-08 437/week @ 2024-09-15 542/week @ 2024-09-22 631/week @ 2024-09-29 1184/week @ 2024-10-06 1042/week @ 2024-10-13 1025/week @ 2024-10-20 1163/week @ 2024-10-27 848/week @ 2024-11-03 847/week @ 2024-11-10 762/week @ 2024-11-17 828/week @ 2024-11-24 919/week @ 2024-12-01 891/week @ 2024-12-08

3,512 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