Struct lsp_server::Connection [−][src]
Expand description
Connection is just a pair of channels of LSP messages.
Fields
sender: Sender<Message>
receiver: Receiver<Message>
Implementations
Create connection over standard in/standard out.
Use this to create a real language server.
Create connection over standard in/sockets out.
Use this to create a real language server.
Creates a pair of connected connections.
Use this for testing.
Starts the initialization process by waiting for an initialize
request from the client. Use this for more advanced customization than
initialize
can provide.
Returns the request id and serialized InitializeParams
from the client.
Example
use std::error::Error; use lsp_types::{ClientCapabilities, InitializeParams, ServerCapabilities}; use lsp_server::{Connection, Message, Request, RequestId, Response}; fn main() -> Result<(), Box<dyn Error + Sync + Send>> { // Create the transport. Includes the stdio (stdin and stdout) versions but this could // also be implemented to use sockets or HTTP. let (connection, io_threads) = Connection::stdio(); // Run the server let (id, params) = connection.initialize_start()?; let init_params: InitializeParams = serde_json::from_value(params).unwrap(); let client_capabilities: ClientCapabilities = init_params.capabilities; let server_capabilities = ServerCapabilities::default(); let initialize_data = serde_json::json!({ "capabilities": server_capabilities, "serverInfo": { "name": "lsp-server-test", "version": "0.1" } }); connection.initialize_finish(id, initialize_data)?; // ... Run main loop ... Ok(()) }
pub fn initialize_finish(
&self,
initialize_id: RequestId,
initialize_result: Value
) -> Result<(), ProtocolError>
pub fn initialize_finish(
&self,
initialize_id: RequestId,
initialize_result: Value
) -> Result<(), ProtocolError>
Finishes the initialization process by sending an InitializeResult
to the client
Initialize the connection. Sends the server capabilities
to the client and returns the serialized client capabilities
on success. If more fine-grained initialization is required use
initialize_start
/initialize_finish
.
Example
use std::error::Error; use lsp_types::ServerCapabilities; use lsp_server::{Connection, Message, Request, RequestId, Response}; fn main() -> Result<(), Box<dyn Error + Sync + Send>> { // Create the transport. Includes the stdio (stdin and stdout) versions but this could // also be implemented to use sockets or HTTP. let (connection, io_threads) = Connection::stdio(); // Run the server let server_capabilities = serde_json::to_value(&ServerCapabilities::default()).unwrap(); let initialization_params = connection.initialize(server_capabilities)?; // ... Run main loop ... Ok(()) }
If req
is Shutdown
, respond to it and return true
, otherwise return false
Auto Trait Implementations
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection