Expand description
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;
}
Re-exports§
pub extern crate lsp_types;
Modules§
- A subset of JSON-RPC types used by the Language Server Protocol.
Structs§
- Handle for communicating with the language client.
- A loopback channel for server-to-client communication.
- Error that occurs when attempting to call the language server after it has already exited.
- Service abstraction for the Language Server Protocol.
- A builder to customize the properties of an
LspService
. - Server for processing requests and responses on standard I/O or TCP.
Traits§
- Trait implemented by language server backends.
- Trait implemented by client loopback sockets.
Attribute Macros§
- A re-export of
async-trait
for convenience.