### Building and serving an LspService with custom_method Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Example of building an LspService with a custom method and serving it. Shows the full setup: build, custom_method, finish, and Server::serve. ```rust let (service, socket) = LspService::build(|client| Backend { client }) .custom_method("custom/ping", Backend::ping) .finish(); Server::new(stdin, stdout, socket).serve(service).await; ``` -------------------------------- ### Basic progress usage Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/progress.md Basic usage example from the doc comment in src/service/client.rs. It creates a progress with a message and starting percentage, reports progress in a loop, and finishes with a message. ```rust let progress = self .client .progress(work_done_token, "Progress Title") .with_message("Working...") .with_percentage(0) .begin() .await; for percent in 1..=100 { let msg = format!("Working... [{percent}/100]"); progress.report_with_message(msg, percent).await; } progress.finish_with_message("Done!").await; ``` -------------------------------- ### initialize handler example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Example implementation of the `initialize` handler. Returns an `InitializeResult` with server info (name and version from `CARGO_PKG_VERSION`) and capabilities enabling hover and completion providers. Uses `tower_lsp::async_trait`. ```rust #[tower_lsp::async_trait] impl LanguageServer for Backend { async fn initialize(&self, _: InitializeParams) -> Result { Ok(InitializeResult { server_info: Some(ServerInfo { name: "my-server".into(), version: Some(env!("CARGO_PKG_VERSION").into()), }), capabilities: ServerCapabilities { hover_provider: Some(HoverProviderCapability::Simple(true)), completion_provider: Some(CompletionOptions::default()), ..Default::default() }, ..Default::default() }) } } ``` -------------------------------- ### Minimal tower-lsp language server example Source: https://github.com/ebkalderon/tower-lsp/blob/master/README.md Complete example of a minimal language server using tower-lsp. Implements the LanguageServer trait with initialize, initialized, and shutdown handlers, then serves the service over stdio with tokio. ```rust 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 { Ok(InitializeResult::default()) } async fn initialized(&self, _: InitializedParams) { self.client .log_message(MessageType::INFO, "server initialized!") .await; } async fn shutdown(&self) -> Result<()> { Ok(()) } } #[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; } ``` -------------------------------- ### TCP server example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md TCP server example from examples/tcp.rs. Connects to a TCP stream, splits it into read and write halves, and serves the LSP service. ```rust let stream = TcpStream::connect("127.0.0.1:9257").await.unwrap(); let (read, write) = tokio::io::split(stream); let (service, socket) = LspService::new(|client| Backend { client }); Server::new(read, write, socket).serve(service).await; ``` -------------------------------- ### shutdown handler example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Example implementation of the `shutdown` handler. Returns `Ok(())` to acknowledge the shutdown request. ```rust async fn shutdown(&self) -> Result<()> { Ok(()) } ``` -------------------------------- ### initialized handler example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Example implementation of the `initialized` notification handler. Logs an info message to the client using `self.client.log_message`. ```rust async fn initialized(&self, _: InitializedParams) { self.client .log_message(MessageType::INFO, "server initialized!") .await; } ``` -------------------------------- ### Basic stdio server Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md Basic stdio server example. Creates an LspService with a Backend, then serves it using stdin and stdout streams. ```rust let (service, socket) = LspService::new(|client| Backend { client }); Server::new(tokio::io::stdin(), tokio::io::stdout(), socket) .serve(service) .await; ``` -------------------------------- ### LspService::new usage example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Creates a service and socket using LspService::new, then serves it with Server::new. The init closure receives the client handle and returns the backend. ```rust let (service, socket) = LspService::new(|client| Backend { client }); Server::new(stdin, stdout, socket).serve(service).await; ``` -------------------------------- ### Router usage example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Creates a Router with a Mock server and registers an 'echo' method using layer_fn. ```rust let mut router: Router = Router::new(Mock); router.method("echo", Mock::echo, layer_fn(|s| s)); ``` -------------------------------- ### Server::serve Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md Starts the server and processes incoming messages until termination. ```APIDOC ## Server::serve ### Description Drives the server pipeline until stdin reaches EOF, the service errors, or the output closes. It handles incoming requests, routes client responses, and writes server responses. ### Method `pub async fn serve(self, mut service: T) where T: Service> + Send + 'static, T::Error: Into>, T::Future: Send` ### Parameters - **service** (`T`) - Required - The language server service that processes requests. ### Example ```rust Server::new(stdin, stdout, socket) .serve(service) .await; ``` ``` -------------------------------- ### Example: cancellable bounded progress stream Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/progress.md Shows how to create a cancellable, bounded progress stream, report progress with messages and percentages, and finish with a message. Note that tower-lsp does not handle `workDoneProgress/cancel`; you must handle cancellation yourself. ```rust let progress = self .client .progress(token, "Linking dependencies") .with_percentage(0) .with_cancel_button() .begin() .await; for (i, dep) in deps.iter().enumerate() { progress .report_with_message(dep.name.clone(), ((i + 1) * 100 / deps.len()) as u32, Some(true)) .await; } progress.finish_with_message("Done!").await; ``` -------------------------------- ### Building a Request with RequestBuilder Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Demonstrates building a JSON-RPC request using the RequestBuilder. The example sets a method, params, and an id, then calls finish to produce the Request. ```rust let request = Request::build("my/method") .params(json!({"foo": 123})) .id(1) .finish(); ``` -------------------------------- ### Response usage example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Shows creating an error response and checking its state. Uses Error::method_not_found and asserts the id. ```rust let resp = Response::from_error(Id::from(1), Error::method_not_found()); assert!(resp.is_error()); let (id, body) = resp.into_parts(); assert_eq!(id, Id::Number(1)); ``` -------------------------------- ### textDocument/inlayHint Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get inlay hints for a text document. ```APIDOC ## textDocument/inlayHint ### Description Request to get inlay hints for a text document. ### Method REQ ### Endpoint textDocument/inlayHint ### Parameters #### Request Body - **InlayHintParams** (object) - Required - Parameters for the inlay hint request. ### Response #### Success Response - **Option>** - A list of inlay hints, if any. ``` -------------------------------- ### Request::build Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Starts building a new JSON-RPC request or notification. ```APIDOC ## Request::build ### Description Starts building a new JSON-RPC request or notification. ### Method Constructor ### Signature ```rust pub fn build(method: M) -> RequestBuilder where M: Into> ``` ### Parameters - **method** (M) - Required - The method name for the request. ### Returns - **RequestBuilder** - A builder for constructing a `Request`. ``` -------------------------------- ### Basic tower-lsp LanguageServer implementation Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Basic implementation of a LanguageServer for tower-lsp, as shown in the README at src/lib.rs:20-56. Implements initialize, initialized, shutdown, completion, and hover handlers. The completion handler returns Ok(None) when the cursor is at the start of a line, and the hover handler returns a simple string. ```rust 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 { 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, params: CompletionParams) -> Result> { // Return `Ok(None)` when there is nothing to complete. if params.text_document_position_params.position.character == 0 { return Ok(None); } Ok(Some(CompletionResponse::Array(vec![ CompletionItem::new_simple("Hello".to_string(), "Some detail".to_string()), ]))) } async fn hover(&self, _: HoverParams) -> Result> { Ok(Some(Hover { contents: HoverContents::Scalar(MarkedString::String("You're hovering!".to_string())), range: None, })) } } ``` -------------------------------- ### Id usage example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Shows how to create an Id from an integer and use it in a Request. The From conversion is used. ```rust let id: Id = 42.into(); let req = Request::build("my/method").id(id).finish(); ``` -------------------------------- ### workspace/diagnostic Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get diagnostics for the workspace. ```APIDOC ## workspace/diagnostic ### Description Request to get diagnostics for the workspace. ### Method REQ ### Endpoint workspace/diagnostic ### Parameters #### Request Body - **WorkspaceDiagnosticParams** (object) - Required - Parameters for the workspace diagnostic request. ### Response #### Success Response - **WorkspaceDiagnosticReportResult** - The workspace diagnostic report result. ``` -------------------------------- ### Registering custom methods with custom_method Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Example of registering custom methods with LspServiceBuilder. Shows a request handler returning Result and a notification handler taking params, then building the service. ```rust impl Mock { async fn request(&self) -> Result { Ok(123) } async fn notification_params(&self, params: Value) { // ... } } let (service, socket) = LspService::build(|_| Mock) .custom_method("custom/request", Mock::request) .custom_method("custom/notificationParams", Mock::notification_params) .finish(); ``` -------------------------------- ### LspService::inner usage example Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Accesses the inner backend method after building a service with a mock backend. ```rust let (service, _) = LspService::build(|_| Mock).finish(); service.inner().some_backend_method().await; ``` -------------------------------- ### Progress Builder Methods Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/progress.md Builder methods for the `Progress` type, used to configure and start a work-done progress stream. ```APIDOC ## `Progress::with_percentage` ### Description Sets the starting percentage for the progress stream, transitioning the progress from unbounded to bounded (0–100%). This method is only available on `Progress`. ### Method `with_percentage` ### Signature `pub fn with_percentage(self, start_percentage: u32) -> Progress` ### Parameters - `start_percentage` (u32) - Required - The starting percentage (100 = 100%). ### Returns `Progress` - A progress builder with bounded kind. ``` ```APIDOC ## `Progress::with_cancel_button` ### Description Enables a cancel button in the client UI by setting `cancellable: Some(true)` in the begin message. This method is only available on `Progress`. ### Method `with_cancel_button` ### Signature `pub fn with_cancel_button(self) -> Progress` ### Returns `Progress` - A progress builder with cancellable kind. ``` ```APIDOC ## `Progress::with_message` ### Description Sets an optional detailed message to show alongside the title. This method is available on any `Progress`. ### Method `with_message` ### Signature `pub fn with_message(mut self, message: M) -> Self where M: Into` ### Parameters - `message` (M) - Required - The message to display, convertible into `String`. ### Returns `Self` - The progress builder with the message set. ``` ```APIDOC ## `Progress::begin` ### Description Emits the `$/progress` Begin notification (gated on server initialization) and returns the ongoing handle. This method consumes the builder. ### Method `begin` ### Signature `pub async fn begin(self) -> OngoingProgress` ### Returns `OngoingProgress` - The ongoing progress handle for reporting updates. ``` -------------------------------- ### Markdown link style example Source: https://github.com/ebkalderon/tower-lsp/blob/master/CONTRIBUTING.md Use reference-style Markdown links for external URLs and inline-style for same-page anchors. Lines must not exceed 80 characters. ```markdown Here is some [example text] with a link in it. While we are at it, here is yet yet [another link][al], but shorter. If we are linking to [an anchor](#anchor) on the same page, we can do this inline. [example text]: https://some.url/ [al]: https://another.url/ ``` -------------------------------- ### initialized Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Notification sent after the client received the `initialize` response. Currently an empty params struct. Used, for example, to dynamically register capabilities with the client. ```APIDOC ## initialized ### Description Notification sent after the client received the `initialize` response. Currently an empty params struct. Used, for example, to dynamically register capabilities with the client. ### Method RPC notification: `initialized` ### Signature ```rust #[rpc(name = "initialized")] async fn initialized(&self, params: InitializedParams) { let _ = params; } ``` ### Parameters - `params` (InitializedParams) - Required - Notification sent after the client received the `initialize` response. Currently an empty params struct. ### Returns `()` - A notification; no response is sent. Default implementation ignores the params. ### Example ```rust async fn initialized(&self, _: InitializedParams) { self.client .log_message(MessageType::INFO, "server initialized!") .await; } ``` ``` -------------------------------- ### Setting concurrency level to 1 Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md Example of setting concurrency level to 1 for sequential processing. ```rust Server::new(stdin, stdout, socket) .concurrency_level(1) .serve(service) .await; ``` -------------------------------- ### initialize Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Initializes the language server. This is the first request sent from the client and contains client capabilities, root URI, workspace folders, trace level, and process ID. Returns the capabilities and optional server info the client should use for the rest of the session. ```APIDOC ## initialize ### Description Initializes the language server. This is the first request sent from the client and contains client capabilities, root URI, workspace folders, trace level, and process ID. Returns the capabilities and optional server info the client should use for the rest of the session. ### Method RPC method: `initialize` ### Signature ```rust #[rpc(name = "initialize")] async fn initialize(&self, params: InitializeParams) -> Result; ``` ### Parameters - `params` (InitializeParams) - Required - The first request sent from the client; contains client capabilities, root URI, workspace folders, trace level, and process ID. ### Returns `Result` - The capabilities and optional server info the client should use for the rest of the session. ### Errors Returning `Err` produces a JSON-RPC error response. If this request is sent while the server is not in the `Uninitialized` state, the `Initialize` middleware answers immediately with `-32600` invalid request without invoking the handler. ### Example ```rust #[tower_lsp::async_trait] impl LanguageServer for Backend { async fn initialize(&self, _: InitializeParams) -> Result { Ok(InitializeResult { server_info: Some(ServerInfo { name: "my-server".into(), version: Some(env!("CARGO_PKG_VERSION").into()), }), capabilities: ServerCapabilities { hover_provider: Some(HoverProviderCapability::Simple(true)), completion_provider: Some(CompletionOptions::default()), ..Default::default() }, ..Default::default() }) } } ``` ``` -------------------------------- ### textDocument/diagnostic Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get diagnostics for a text document. ```APIDOC ## textDocument/diagnostic ### Description Request to get diagnostics for a text document. ### Method REQ ### Endpoint textDocument/diagnostic ### Parameters #### Request Body - **DocumentDiagnosticParams** (object) - Required - Parameters for the diagnostic request. ### Response #### Success Response - **DocumentDiagnosticReportResult** - The diagnostic report result. ``` -------------------------------- ### textDocument/documentSymbol Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get symbols in a text document. ```APIDOC ## textDocument/documentSymbol ### Description Request to get symbols in a text document. ### Method REQ ### Endpoint textDocument/documentSymbol ### Parameters #### Request Body - **DocumentSymbolParams** (object) - Required - Parameters for the document symbol request. ### Response #### Success Response - **Option** - The document symbol response, if any. ``` -------------------------------- ### textDocument/documentColor Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get color information for a text document. ```APIDOC ## textDocument/documentColor ### Description Request to get color information for a text document. ### Method REQ ### Endpoint textDocument/documentColor ### Parameters #### Request Body - **DocumentColorParams** (object) - Required - Parameters for the document color request. ### Response #### Success Response - **Vec** - A list of color information. ``` -------------------------------- ### Server::new Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md Constructs a new `Server` instance with the specified input/output streams and loopback socket. ```APIDOC ## Server::new ### Description Creates a new `Server` instance with the given input stream, output stream, and loopback socket. The server multiplexes bidirectional streams through a transport such as stdio, TCP, or WebSocket. ### Method `pub fn new(stdin: I, stdout: O, socket: L) -> Self` ### Parameters - **stdin** (`I: AsyncRead + Unpin`) - Required - Stream the client writes JSON-RPC messages to. - **stdout** (`O: AsyncWrite`) - Required - Stream server messages are written to. - **socket** (`L: Loopback`) - Required - The server→client loopback socket (typically `ClientSocket`). ### Example ```rust let (service, socket) = LspService::new(|client| Backend { client }); Server::new(tokio::io::stdin(), tokio::io::stdout(), socket) .serve(service) .await; ``` ``` -------------------------------- ### textDocument/codeAction Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get code actions for a text document. ```APIDOC ## textDocument/codeAction ### Description Request to get code actions for a text document. ### Method REQ ### Endpoint textDocument/codeAction ### Parameters #### Request Body - **CodeActionParams** (object) - Required - Parameters for the code action request. ### Response #### Success Response - **Option** - The code action response, if any. ``` -------------------------------- ### textDocument/moniker Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get monikers for a symbol in a text document. ```APIDOC ## textDocument/moniker ### Description Request to get monikers for a symbol in a text document. ### Method REQ ### Endpoint textDocument/moniker ### Parameters #### Request Body - **MonikerParams** (object) - Required - Parameters for the moniker request. ### Response #### Success Response - **Option>** - A list of monikers, if any. ``` -------------------------------- ### LspService::new Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Creates a new LspService and its associated ClientSocket. The provided closure receives a Client handle and returns the backend instance. ```APIDOC ## LspService::new ### Description Creates a new `LspService` and its associated `ClientSocket`. The provided closure receives a `Client` handle and returns the backend instance. ### Method `LspService::new` ### Signature ```rust pub fn new(init: F) -> (Self, ClientSocket) where F: FnOnce(Client) -> S, ``` ### Parameters - **init** (`F: FnOnce(Client) -> S`) - Required - Closure receiving the server-to-client handle and returning the backend. ### Returns - `(LspService, ClientSocket)` - The service and the loopback socket for client communication. ### Example ```rust let (service, socket) = LspService::new(|client| Backend { client }); Server::new(stdin, stdout, socket).serve(service).await; ``` ``` -------------------------------- ### textDocument/inlineValue Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get inline values for a text document. ```APIDOC ## textDocument/inlineValue ### Description Request to get inline values for a text document. ### Method REQ ### Endpoint textDocument/inlineValue ### Parameters #### Request Body - **InlineValueParams** (object) - Required - Parameters for the inline value request. ### Response #### Success Response - **Option>** - A list of inline values, if any. ``` -------------------------------- ### textDocument/semanticTokens/full Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get semantic tokens for a text document. ```APIDOC ## textDocument/semanticTokens/full ### Description Request to get semantic tokens for a text document. ### Method REQ ### Endpoint textDocument/semanticTokens/full ### Parameters #### Request Body - **SemanticTokensParams** (object) - Required - Parameters for the semantic tokens request. ### Response #### Success Response - **Option** - The semantic tokens result, if any. ``` -------------------------------- ### LspService::build signature Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Same as new but returns an LspServiceBuilder so custom JSON-RPC methods can be registered before finishing. ```rust pub fn build(init: F) -> LspServiceBuilder where F: FnOnce(Client) -> S, ``` -------------------------------- ### textDocument/selectionRange Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get selection ranges for a text document. ```APIDOC ## textDocument/selectionRange ### Description Request to get selection ranges for a text document. ### Method REQ ### Endpoint textDocument/selectionRange ### Parameters #### Request Body - **SelectionRangeParams** (object) - Required - Parameters for the selection range request. ### Response #### Success Response - **Option>** - A list of selection ranges, if any. ``` -------------------------------- ### initialize Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Initialization request that must be implemented by the server. ```APIDOC ## initialize ### Description Initializes the language server. Must be implemented and runs once. Duplicate requests return error code -32600. ### Method REQ (request) ### Endpoint `initialize` ### Parameters #### Request Body - **params** (`InitializeParams`) - Required - The initialization parameters. ### Response #### Success Response - **result** (`InitializeResult`) - The initialization result. #### Error Response - **code** (`-32600`) - Duplicate request. ``` -------------------------------- ### textDocument/foldingRange Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get folding ranges for a text document. ```APIDOC ## textDocument/foldingRange ### Description Request to get folding ranges for a text document. ### Method REQ ### Endpoint textDocument/foldingRange ### Parameters #### Request Body - **FoldingRangeParams** (object) - Required - Parameters for the folding range request. ### Response #### Success Response - **Option>** - A list of folding ranges, if any. ``` -------------------------------- ### finish Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Constructs the `LspService` and returns it along with the server-to-client communication channel. ```APIDOC ## `finish` ### Description Constructs the `LspService` and returns it along with the server-to-client communication channel. ### Method `finish` ### Signature ```rust pub fn finish(self) -> (LspService, ClientSocket) ``` ### Returns - **LspService** - The constructed LSP service. - **ClientSocket** - The server-to-client communication channel. ### Example ```rust let (service, socket) = LspService::build(|client| Backend { client }) .custom_method("custom/ping", Backend::ping) .finish(); Server::new(stdin, stdout, socket).serve(service).await; ``` ``` -------------------------------- ### textDocument/codeLens Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get code lenses for a text document. ```APIDOC ## textDocument/codeLens ### Description Request to get code lenses for a text document. ### Method REQ ### Endpoint textDocument/codeLens ### Parameters #### Request Body - **CodeLensParams** (object) - Required - Parameters for the code lens request. ### Response #### Success Response - **Option>** - A list of code lenses, if any. ``` -------------------------------- ### typeHierarchy/subtypes Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get subtypes of a type hierarchy item. ```APIDOC ## typeHierarchy/subtypes ### Description Request to get subtypes of a type hierarchy item. ### Method REQ ### Endpoint typeHierarchy/subtypes ### Parameters #### Request Body - **TypeHierarchySubtypesParams** (object) - Required - Parameters for the subtypes request. ### Response #### Success Response - **Option>** - A list of subtype items, if any. ``` -------------------------------- ### Server::new constructor Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/server.md Constructor for Server. Takes the input stream, output stream, and loopback socket. Requires I: AsyncRead + Unpin, O: AsyncWrite, L: Loopback. ```rust pub fn new(stdin: I, stdout: O, socket: L) -> Self ``` -------------------------------- ### typeHierarchy/supertypes Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get supertypes of a type hierarchy item. ```APIDOC ## typeHierarchy/supertypes ### Description Request to get supertypes of a type hierarchy item. ### Method REQ ### Endpoint typeHierarchy/supertypes ### Parameters #### Request Body - **TypeHierarchySupertypesParams** (object) - Required - Parameters for the supertypes request. ### Response #### Success Response - **Option>** - A list of supertype items, if any. ``` -------------------------------- ### textDocument/colorPresentation Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get color presentations for a color in a text document. ```APIDOC ## textDocument/colorPresentation ### Description Request to get color presentations for a color in a text document. ### Method REQ ### Endpoint textDocument/colorPresentation ### Parameters #### Request Body - **ColorPresentationParams** (object) - Required - Parameters for the color presentation request. ### Response #### Success Response - **Vec** - A list of color presentations. ``` -------------------------------- ### Basic client method usage Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/client.md Basic usage of the client methods: log a message, publish diagnostics, and fetch configuration. The configuration call returns a jsonrpc::Result and uses the ? operator. ```rust self.client .log_message(MessageType::INFO, "server initialized!") .await; self.client.publish_diagnostics(uri, diagnostics, Some(version)).await; let config = self.client.configuration(vec![ConfigurationItem { scope_uri: None, section: Some("myServer".to_string()), }]).await?; ``` -------------------------------- ### textDocument/signatureHelp Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get signature help for a position in a text document. ```APIDOC ## textDocument/signatureHelp ### Description Request to get signature help for a position in a text document. ### Method REQ ### Endpoint textDocument/signatureHelp ### Parameters #### Request Body - **SignatureHelpParams** (object) - Required - Parameters for the signature help request. ### Response #### Success Response - **Option** - The signature help, if any. ``` -------------------------------- ### textDocument/completion Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get completion items for a position in a text document. ```APIDOC ## textDocument/completion ### Description Request to get completion items for a position in a text document. ### Method REQ ### Endpoint textDocument/completion ### Parameters #### Request Body - **CompletionParams** (object) - Required - Parameters for the completion request. ### Response #### Success Response - **Option** - The completion response, if any. ``` -------------------------------- ### textDocument/semanticTokens/range Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get semantic tokens for a range in a text document. ```APIDOC ## textDocument/semanticTokens/range ### Description Request to get semantic tokens for a range in a text document. ### Method REQ ### Endpoint textDocument/semanticTokens/range ### Parameters #### Request Body - **SemanticTokensRangeParams** (object) - Required - Parameters for the semantic tokens range request. ### Response #### Success Response - **Option** - The semantic tokens range result, if any. ``` -------------------------------- ### Client Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/client.md Documentation for the Client type, including its structure and initialization gating behavior. ```APIDOC ## Client ### Description Handle for communicating with the language client. Cheap to clone (`Arc`-backed); pass it into the backend via the `LspService::new(|client| ...)` closure, or use the `Client::progress` handle. Also implements `tower::Service` (`Response = Option`, `Error = ExitedError`) so it can be used with middleware; `Debug` is implemented manually. ### Type ```rust #[derive(Clone)] pub struct Client { inner: Arc, } ``` ### Initialization Gating Methods that *send requests* (`register_capability`, `unregister_capability`, `show_document`, `code_lens_refresh`, `semantic_tokens_refresh`, `inline_value_refresh`, `inlay_hint_refresh`, `workspace_diagnostic_refresh`, `configuration`, `workspace_folders`, `apply_edit`, `show_message_request`, `send_request`) return `Err` with JSON-RPC code `-32002` ("Server not initialized") when called before the server is initialized. Methods that *send notifications through* `send_notification` (`publish_diagnostics`, `progress`) are silently suppressed ("server not initialized, supressing message") when not initialized. `show_message`, `log_message` and `telemetry_event` use the unchecked path and are sent regardless of state. After `shutdown` (state `ShutDown`), outgoing requests/notifications are still permitted. ``` -------------------------------- ### textDocument/semanticTokens/full/delta Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get semantic tokens delta for a text document. ```APIDOC ## textDocument/semanticTokens/full/delta ### Description Request to get semantic tokens delta for a text document. ### Method REQ ### Endpoint textDocument/semanticTokens/full/delta ### Parameters #### Request Body - **SemanticTokensDeltaParams** (object) - Required - Parameters for the semantic tokens delta request. ### Response #### Success Response - **Option** - The semantic tokens delta result, if any. ``` -------------------------------- ### textDocument/hover Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get hover information for a position in a text document. ```APIDOC ## textDocument/hover ### Description Request to get hover information for a position in a text document. ### Method REQ ### Endpoint textDocument/hover ### Parameters #### Request Body - **HoverParams** (object) - Required - Parameters for the hover request. ### Response #### Success Response - **Option** - The hover information, if any. ``` -------------------------------- ### Router::new Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/jsonrpc.md Creates a new Router with the given shared server state. ```APIDOC ## Router::new ### Description Creates a new Router with the given shared server state. ### Method `pub fn new(server: S) -> Self` ### Parameters - `server` (S) - The shared server state. ### Returns A new `Router` instance. ``` -------------------------------- ### LspService::build usage with custom method Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Builds a service with a custom method 'custom/request' and finishes to obtain the service and socket. ```rust let (service, socket) = LspService::build(|client| Backend { client }) .custom_method("custom/request", Mock::request) .finish(); ``` -------------------------------- ### callHierarchy/outgoingCalls Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get outgoing calls for a call hierarchy item. ```APIDOC ## callHierarchy/outgoingCalls ### Description Request to get outgoing calls for a call hierarchy item. ### Method REQ ### Endpoint callHierarchy/outgoingCalls ### Parameters #### Request Body - **CallHierarchyOutgoingCallsParams** (object) - Required - Parameters for the outgoing calls request. ### Response #### Success Response - **Option>** - A list of outgoing calls, if any. ``` -------------------------------- ### LspService::new signature Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Constructor that takes an init closure receiving a Client and returning the backend. Returns a tuple of LspService and ClientSocket. The ClientSocket is the loopback half of client communication, to be passed to Server::new. ```rust pub fn new(init: F) -> (Self, ClientSocket) where F: FnOnce(Client) -> S, ``` -------------------------------- ### callHierarchy/incomingCalls Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get incoming calls for a call hierarchy item. ```APIDOC ## callHierarchy/incomingCalls ### Description Request to get incoming calls for a call hierarchy item. ### Method REQ ### Endpoint callHierarchy/incomingCalls ### Parameters #### Request Body - **CallHierarchyIncomingCallsParams** (object) - Required - Parameters for the incoming calls request. ### Response #### Success Response - **Option>** - A list of incoming calls, if any. ``` -------------------------------- ### workspace/executeCommand Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/language-server.md Executes a command on the server. ```APIDOC ## workspace/executeCommand ### Description Executes a command on the server. ### Method POST ### Endpoint `workspace/executeCommand` ### Parameters #### Request Body - **params** (ExecuteCommandParams) - Required - The parameters for the command execution. ### Response #### Success Response (200) - **result** (Option) - The result of the command, or `null` if none. ### Default Returns an error by default. ``` -------------------------------- ### Workspace and Infrastructure Methods Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Documentation for the workspace and infrastructure methods of the tower-lsp language server protocol. ```APIDOC ## workspace/symbol ### Description Request to retrieve all symbols matching a query in the workspace. ### Method REQ ### Endpoint workspace/symbol ### Parameters #### Request Body - **WorkspaceSymbolParams** (object) - Required - The parameters for the workspace symbol request. ### Response #### Success Response - **Option>** - A list of symbol information or null. ``` ```APIDOC ## workspaceSymbol/resolve ### Description Request to resolve additional information for a workspace symbol. ### Method REQ ### Endpoint workspaceSymbol/resolve ### Parameters #### Request Body - **WorkspaceSymbol** (object) - Required - The workspace symbol to resolve. ### Response #### Success Response - **WorkspaceSymbol** - The resolved workspace symbol. ``` ```APIDOC ## workspace/didChangeConfiguration ### Description Notification that the workspace configuration has changed. ### Method NOT ### Endpoint workspace/didChangeConfiguration ### Parameters #### Request Body - **DidChangeConfigurationParams** (object) - Required - The parameters for the configuration change notification. ``` ```APIDOC ## workspace/didChangeWorkspaceFolders ### Description Notification that the workspace folders have changed. ### Method NOT ### Endpoint workspace/didChangeWorkspaceFolders ### Parameters #### Request Body - **DidChangeWorkspaceFoldersParams** (object) - Required - The parameters for the workspace folders change notification. ``` ```APIDOC ## workspace/willCreateFiles ### Description Request that is fired before files are created in the workspace. ### Method REQ ### Endpoint workspace/willCreateFiles ### Parameters #### Request Body - **CreateFilesParams** (object) - Required - The parameters for the file creation request. ### Response #### Success Response - **Option** - A workspace edit to apply or null. ``` ```APIDOC ## workspace/didCreateFiles ### Description Notification that files were created in the workspace. ### Method NOT ### Endpoint workspace/didCreateFiles ### Parameters #### Request Body - **CreateFilesParams** (object) - Required - The parameters for the file creation notification. ``` ```APIDOC ## workspace/willRenameFiles ### Description Request that is fired before files are renamed in the workspace. ### Method REQ ### Endpoint workspace/willRenameFiles ### Parameters #### Request Body - **RenameFilesParams** (object) - Required - The parameters for the file rename request. ### Response #### Success Response - **Option** - A workspace edit to apply or null. ``` ```APIDOC ## workspace/didRenameFiles ### Description Notification that files were renamed in the workspace. ### Method NOT ### Endpoint workspace/didRenameFiles ### Parameters #### Request Body - **RenameFilesParams** (object) - Required - The parameters for the file rename notification. ``` ```APIDOC ## workspace/willDeleteFiles ### Description Request that is fired before files are deleted in the workspace. ### Method REQ ### Endpoint workspace/willDeleteFiles ### Parameters #### Request Body - **DeleteFilesParams** (object) - Required - The parameters for the file deletion request. ### Response #### Success Response - **Option** - A workspace edit to apply or null. ``` ```APIDOC ## workspace/didDeleteFiles ### Description Notification that files were deleted in the workspace. ### Method NOT ### Endpoint workspace/didDeleteFiles ### Parameters #### Request Body - **DeleteFilesParams** (object) - Required - The parameters for the file deletion notification. ``` ```APIDOC ## workspace/didChangeWatchedFiles ### Description Notification that watched files have changed in the workspace. ### Method NOT ### Endpoint workspace/didChangeWatchedFiles ### Parameters #### Request Body - **DidChangeWatchedFilesParams** (object) - Required - The parameters for the watched files change notification. ``` ```APIDOC ## workspace/executeCommand ### Description Request to execute a command in the workspace. ### Method REQ ### Endpoint workspace/executeCommand ### Parameters #### Request Body - **ExecuteCommandParams** (object) - Required - The parameters for the command execution request. ### Response #### Success Response - **Option** - The result of the command execution or null. ``` ```APIDOC ## $/cancelRequest ### Description Notification to cancel a pending request. The request with the given ID is canceled and its future resolves to -32800 (canceled). Unknown IDs are ignored. ### Method NOT ### Endpoint $/cancelRequest ### Parameters #### Request Body - **CancelParams** (object) - Required - Contains the ID of the request to cancel. The `id` field is of type `NumberOrString`. ``` -------------------------------- ### textDocument/linkedEditingRange Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/endpoints.md Request to get linked editing ranges for a position in a text document. ```APIDOC ## textDocument/linkedEditingRange ### Description Request to get linked editing ranges for a position in a text document. ### Method REQ ### Endpoint textDocument/linkedEditingRange ### Parameters #### Request Body - **LinkedEditingRangeParams** (object) - Required - Parameters for the linked editing range request. ### Response #### Success Response - **Option** - The linked editing ranges, if any. ``` -------------------------------- ### Progress builder methods Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/progress.md Builder methods on Progress. with_percentage transitions to Bounded, with_cancel_button sets cancellable to true, with_message adds a detailed message, and begin emits the Begin notification and returns OngoingProgress. ```rust pub fn with_percentage(self, start_percentage: u32) -> Progress // only on Progress pub fn with_cancel_button(self) -> Progress // only on Progress pub fn with_message(mut self, message: M) -> Self where M: Into // any Progress pub async fn begin(self) -> OngoingProgress ``` -------------------------------- ### LspService::build Source: https://github.com/ebkalderon/tower-lsp/blob/master/_autodocs/api-reference/lsp-service.md Creates an LspServiceBuilder for the service, allowing custom JSON-RPC methods to be registered before finishing. ```APIDOC ## LspService::build ### Description Creates an `LspServiceBuilder` for the service, allowing custom JSON-RPC methods to be registered before finishing. ### Method `LspService::build` ### Signature ```rust pub fn build(init: F) -> LspServiceBuilder where F: FnOnce(Client) -> S, ``` ### Parameters - **init** (`F: FnOnce(Client) -> S`) - Required - Closure receiving the client handle and returning the backend. ### Returns - `LspServiceBuilder` - A builder for configuring the service. ### Example ```rust let (service, socket) = LspService::build(|client| Backend { client }) .custom_method("custom/request", Mock::request) .finish(); ``` ```