1 unstable release
0.1.0 | Aug 23, 2024 |
---|
#217 in Text editors
3,512 downloads per month
Used in 7 crates
(4 directly)
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