LanguageServer

Struct LanguageServer 

Source
pub struct LanguageServer {
    pub output_done_rx: UnboundedReceiver<String>,
    /* private fields */
}

Fields§

§output_done_rx: UnboundedReceiver<String>

Implementations§

Source§

impl LanguageServer

Source

pub fn new( binary: LanguageServerBinary, id: i32, root_path: &Path, capture: Arc<Mutex<Option<String>>>, code_action_kind: Option<Vec<CodeActionKind>>, ) -> Result<Self>

Start a new language server process A process is construct by one io_listener and one listener_loop When sending something to the process, the request will be handled by background task keeping the process lock-free

§Usage
    let binary: LanguageServerBinary = LanguageServerBinary { ... };
    let root_path = Path::new("your-root");
    // Stderr capture will take every stderr response receivered
    // usefull for logging
    let stderr_capture = Arc::new(Mutex::new(...))
    let server =
        LanguageServerProcess::new(binary, 1, root_path, stderr_capture, None)?;
  • binary: See LanguageServerBinary
  • id: id for the server
  • root_path: Root path for the lsp, useful for discovering workspaces
  • capture: Stderr capturer
  • code_action_kind: List of code action kinds that will be registered during startup
Source

pub async fn request<T: Request>(&self, params: T::Params) -> Result<T::Result>

Send a request to the server and get the response back T must be type of request::Request. We had re-exported the module

§Usage
    use chan_rs::lsp_types::request::Initialize;

    let init_params = IntializeParams::default();
    let response = server.request::<Initialize>(init_params)?;
  • params: Parameters for the request
Source

pub async fn notify<T: Notification>(&self, params: T::Params) -> Result<()>

Send a notify to the server, notify requests don’t send response back T must be type of notification::Notification. We had re-exported the module

§Usage
    use chan_rs::lsp_types::notification::Initialized;

    let initialized = IntializedParams::default();
    server.notify::<Initialized>(initialized)?;
  • params: Parameters for the notification
Source

pub fn on_request<T: Request, F, Fut>(&self, f: F) -> Subscription
where T::Params: 'static + Send, F: Send + 'static + FnMut(T::Params) -> Fut, Fut: Send + 'static + Future<Output = Result<T::Result>>,

Register a handler to handle incoming request You can only register on handler for one method

Source

pub fn on_notification<T: Notification, F>(&self, f: F) -> Subscription
where T::Params: 'static + Send, F: Send + 'static + FnMut(T::Params),

Register a handler to handle incoming notification You can only register one handler for one method

Source

pub fn on_io<F>(&self, f: F) -> Subscription
where F: Send + 'static + FnMut(IOKind, &str),

Register a handler to handle stdio You can re-regsiter the handler

Source

pub fn server_id(&self) -> i32

Get the server id

Source

pub fn root_path(&self) -> &PathBuf

Root Path of working project

Source

pub fn working_dir(&self) -> &PathBuf

Working dir of the workspace

Source

pub fn capabilities(&self) -> ServerCapabilities

List of capablilities

Source

pub fn update_capabilities(&self, update: impl FnOnce(&mut ServerCapabilities))

Update the server capabilities

Source

pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>>

List code action kinds

Source

pub fn name(&self) -> &str

The server name

Source

pub fn kill(&mut self) -> Result<()>

Kill the tasks

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.