Struct lsp_server::Connection[][src]

pub struct Connection {
    pub sender: Sender<Message>,
    pub receiver: Receiver<Message>,
}

Connection is just a pair of channels of LSP messages.

Fields

sender: Sender<Message>receiver: Receiver<Message>

Implementations

impl Connection[src]

pub fn stdio() -> (Connection, IoThreads)[src]

Create connection over standard in/standard out.

Use this to create a real language server.

pub fn socket<A: ToSocketAddrs>(addr: A) -> (Connection, IoThreads)[src]

Create connection over standard in/sockets out.

Use this to create a real language server.

pub fn memory() -> (Connection, Connection)[src]

Creates a pair of connected connections.

Use this for testing.

pub fn initialize_start(&self) -> Result<(RequestId, Value), ProtocolError>[src]

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>
[src]

Finishes the initialization process by sending an InitializeResult to the client

pub fn initialize(
    &self,
    server_capabilities: Value
) -> Result<Value, ProtocolError>
[src]

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(())
}

pub fn handle_shutdown(&self, req: &Request) -> Result<bool, ProtocolError>[src]

If req is Shutdown, respond to it and return true, otherwise return false

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.