Struct lsp_server::Connection[][src]

pub struct Connection {
    pub sender: Sender<Message>,
    pub receiver: Receiver<Message>,
}
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(())
}

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.