Expand description
Language Server Protocol (LSP) server abstraction for Tower.
§Example
use lsp_max::jsonrpc::Result;
use lsp_max::lsp_types_max::*;
use lsp_max::{Client, LanguageServer, LspService, Server};
#[derive(Debug)]
struct Backend {
client: Client,
}
#[lsp_max::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 });
let _ = Server::new(stdin, stdout, socket).serve(service).await;
}Re-exports§
pub extern crate lsp_types_max;pub extern crate lsp_max_protocol as max_protocol;
Re-exports§
pub use agent as max_agent;pub use andon as max_andon;pub use live as max_live;pub use runtime as max_runtime;pub use self::service::Client;pub use self::service::ClientSocket;pub use self::service::ExitedError;pub use self::service::LspService;pub use self::service::LspServiceBuilder;pub use language_server::LanguageServer;pub use rule_pack_server::glob_matches;pub use rule_pack_server::ClassifiedFindings;pub use rule_pack_server::Finding;pub use rule_pack_server::Rule;pub use rule_pack_server::RulePack;pub use rule_pack_server::RulePackServer;pub use rule_pack_server::ValidatedRulePackSet;pub use rule_pack_server::WorkspaceIndex;pub use lsp_types_max as lsp_types;pub use lsp_max_lsif as lsif;
Modules§
- agent
- andon
- ast
- Semantic parsing and incremental AST generation via the lsp-max-ast layer.
- client
- closure_
channel - coverage
- LSP 3.18 and LSIF protocol coverage matrices. Protocol coverage matrices for LSP 3.18 and LSIF.
- diagnostics
- Module containing diagnostic update and management functions.
- gate
- Module containing validation gate logic. Validation gate logic for verifying server authorization, state checks, and compliance keys.
- jsonrpc
- A subset of JSON-RPC types used by the Language Server Protocol.
- language_
server - Module containing the
LanguageServertrait and its macro-generated router. - live
- pipeline
- TPOT2-style breed pipeline type system for automated wasm4pm cognitive breed search.
- primitives
- First-class framework primitives:
DocumentStore,DiagnosticSink,debounce. - rule_
pack_ server - Bridge trait eliminating hand-rolled regex-pattern LSP server boilerplate.
RulePackServer— the bridge trait that eliminates the boilerplate every regex-pattern language server had to hand-roll. - runtime
- Runtime utilities for lsp-max servers.
- service
- Service abstraction for language servers.
- workspace_
edit - Module containing helper functions to apply workspace and text edits. Functions to apply workspace edits and text modifications.
Structs§
- Composed
Server - Composed LSP server that coordinates multiple upstream language servers.
- Composition
State - State manager for language server composition.
- Ongoing
Progress - An ongoing stream of progress being reported to the client.
- Progress
- A builder for a new
$/progressstream. - Server
- Server for processing requests and responses on standard I/O or TCP.
- Server
Registry - Registry storing server diagnostic and capability state.
- Snapshot
Record - Record representing a snapshot of the server state.
Enums§
- Source
Health - The health state of an upstream source.
Statics§
- MESH
- Global static instance of the autonomic mesh, used by RPC bridge methods.
- REGISTRY
- Global static instance of the server registry.
Traits§
- Loopback
- Trait implemented by client loopback sockets.
Functions§
- get_
registry - Retrieves a reference to the global server registry.
- reset_
registry_ for_ tests - Reset the global registry to a fresh state. Exposed as a public function for integration tests to prevent shared-state pollution.
Type Aliases§
- Shared
Composition State - Shared thread-safe handle to the composition state.
Attribute Macros§
- async_
trait - A re-export of
async-traitfor convenience.