Server

Struct Server 

Source
pub struct Server<T: TypeProvider> {
    pub connection: Connection<T>,
    /* private fields */
}
Expand description

This struct is a wrapper around the server state, which provides type via the TypeProvider trait. It also contains the connection to the client and all callbacks for the different endpoints.

§Example

use sync_lsp::{Transport, TypeProvider, Server};
 
// For this example, we don't need any state.
struct MyServerState;
 
// This macro provides default implementations for all required types.
#[sync_lsp::type_provider]
impl TypeProvider for MyServerState {}
 
fn main() {
    let transport = Transport::stdio();
    let mut server = Server::new(MyServerState, transport);
 
   //Callbacks can be registered here via the `server.on_*` methods.
   //Note that callbacks may also be registered after the server has been started.
 
    server.serve().unwrap();
}

Fields§

§connection: Connection<T>

Implementations§

Source§

impl<T: TypeProvider> Server<T>

Source

pub fn new(state: T, transport: Transport) -> Server<T>

Creates a new server with the given state and transport.

Source

pub fn process_id(&self) -> Option<u32>

Returns the process id of the server, if one is provided by the client.

Source

pub fn root_uri(&self) -> Option<&str>

Returns the root uri of the workspace, if one is provided by the client.

Source

pub fn initialization_options(&self) -> Option<&T::InitializeOptions>

Returns the initialization options as defined in TypeProvider::InitializeOptions if available and parsed correctly.

Source

pub fn split(&mut self) -> (&mut Connection<T>, &mut T)

Splits the server into its connection and state.

Source

pub fn serve(self) -> Result<(), Error>

Starts the server. This will block the current thread. Until there is either an error or the client sends a shutdown request.

Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_open(&mut self, callback: fn(&mut Server<T>, TextDocumentItem))

Sets the callback that will be called if a file is opened.

§Argument
  • callback - A callback which is called with the following parameters as soon as a file is opened:
    • The server instance receiving the response.
    • The TextDocumentItem of the document that has been opened.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_change( &mut self, callback: fn(&mut Server<T>, VersionedTextDocumentIdentifier, Vec<TextDocumentContentChangeEvent>), )

Sets the callback that will be called if a change to a file is detected.

§Argument
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_will_save( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, TextDocumentSaveReason), )

Sets the callback that will be called to notify the server that a document is about to be saved.

§Argument
  • callback - A callback which is called with the following parameters as soon as a document is about to be saved:
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_will_save_wait_until( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, TextDocumentSaveReason) -> Vec<TextEdit>, )

Sets the callback that will be called to modify a document before it is saved.

§Argument
  • callback - A callback which is called with the following parameters as soon as a document is about to be saved:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The TextDocumentSaveReason that specifies why the document is saved.
    • return - A list of edits to apply to the document.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_save( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Option<String>), )

Sets the callback that will be called if a file is saved.

§Argument
  • callback - A callback which is called with the following parameters as soon as a file is saved:
Source

pub fn set_save_include_text(&mut self, value: bool)

Sets whether the content of the file should be included in the Server::on_save callback.

§Argument
  • value - If true, the content of the file will be included in the callback.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_close(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer))

Sets the callback that will be called if a file is closed.

§Argument
  • callback - A callback which is called with the following parameters as soon as a file is closed:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document that has been closed.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_completion( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> CompletionList<T>, )

Sets the callback that will be called to compute completion items.

§Argument
  • callback - A callback which is called with the following parameters as soon as completion items are requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document for which completions are requested.
    • return - A list of completions to display.
Source

pub fn on_resolve_completion( &mut self, callback: fn(&mut Server<T>, CompletionItem<T>) -> CompletionItem<T>, )

Sets the callback that will be called to compute missing information on completion items, which were previously returned by Server::on_completion.

§Argument
  • callback - A callback which is called with the following parameters as soon a completion can be resolved:
    • The server instance receiving the response.
    • The CompletionItem to resolve.
    • return - The resolved completion.
Source

pub fn set_completion_trigger_character( &mut self, trigger_characters: Vec<String>, )

The client will request completions if one of the characters in trigger_characters is typed.

§Argument
  • trigger_characters - A list of characters that trigger completion.
Source

pub fn snippet_support(&self) -> bool

Returns whether the client supports snippets for completion items.

§Return
  • true if the client supports snippets, false otherwise.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_hover( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Hover, )

Sets the callback that will be called to compute hover information.

§Argument
  • callback - A callback which is called with the following parameters as soon as hover information is requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The Position of the cursor.
    • return - The hover information to display.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_signature_help( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> SignatureHelp, )

Sets the callback that will be called to compute signature help.

§Argument
  • callback - A callback which is called with the following parameters as soon as signature help is requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The Position of the cursor.
    • return - The signature help to display.
Source

pub fn set_signature_help_trigger_characters(&mut self, value: Vec<String>)

Sets the characters that trigger signature help.

§Argument
  • value - The characters that trigger signature help.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_references( &mut self, callback: fn(_: &mut Server<T>, _: TextDocumentIdentifer, _: Position, context: ReferenceContext) -> Vec<Location>, )

Sets the callback that will be called to resolve references.

§Argument
  • callback - A callback which is called with the following parameters as soon as references are requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The Position of the cursor.
    • The ReferenceContext that specifies which references should be returned.
    • return - A list of locations that reference the symbol at the given position.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_document_highlight( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Vec<DocumentHighlight>, )

Sets the callback that will be called to highlight parts of a file.

§Argument
  • callback - A callback which is called with the following parameters as soon as a highlight is requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The Position of the cursor.
    • return - A list of highlights to display.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_document_symbol( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<SymbolInformation>, )

Sets the callback that will be called to compute document symbols.

§Argument
  • callback - A callback which is called with the following parameters as soon as document symbols are requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • return - A list of symbols to display.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_formatting( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, FormattingOptions) -> Vec<TextEdit>, )

Sets the callback that will be called to format a document.

§Argument
  • callback - A callback which is called with the following parameters as soon as a document is formatted:
    • server - The server on which the request was received.
    • document - The TextDocumentIdentifer of the target document.
    • options - The FormattingOptions that specify how the document should be formatted.
    • return - A list of edits to apply to the document.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_range_formatting( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Range, FormattingOptions) -> Vec<TextEdit>, )

Sets the callback that will be called to implement range formatting.

§Argument
  • callback - A callback which is called with the following parameters as soon as a document range is formatted:
    • server - The server on which the request was received.
    • document - The TextDocumentIdentifer of the target document.
    • range - The Range that should be formatted.
    • options - The FormattingOptions that specify how the document should be formatted.
    • return - A list of edits to apply to the document.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_type_formatting( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position, String, FormattingOptions) -> Vec<TextEdit>, )

Sets the callback that will be called to implement on type formatting.

§Argument
  • callback - A callback which is called with the following parameters as soon as a document is formatted:
    • server - The server on which the request was received.
    • document - The TextDocumentIdentifer of the target document.
    • position - The Position of the cursor.
    • options - The FormattingOptions that specify how the document should be formatted.
    • return - A list of edits to apply to the document.
Source

pub fn set_on_type_formatting_first_trigger_character(&mut self, value: String)

Sets the first trigger character that triggers on type formatting.

§Argument
  • value - The first trigger character that triggers formatting.
Source

pub fn set_on_type_formatting_more_trigger_characters( &mut self, value: Vec<String>, )

Sets the additional characters that trigger on type formatting.

§Argument
  • value - Additional characters that trigger formatting.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_definition( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Vec<Location>, )

Sets the callback that will be called to locate a definition.

§Argument
  • callback - A callback which is called with the following parameters to resolve a definition:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document for which a definition is requested.
    • The Position at which a definition is requested.
    • return - A list of Locations to display.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_code_action( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Range, CodeActionContext) -> Vec<T::Command>, )

Sets the callback that will be called to compute code actions.

§Argument
  • callback - A callback which is called with the following parameters as soon as code actions are requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document for which code actions are requested.
    • The Range of the document for which code actions are requested.
    • The CodeActionContext for which code actions are requested.
    • return - A list of commands to execute.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_code_lens( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<CodeLens<T::Command, T::CodeLensData>>, )

Sets the callback that will be called to compute code lenses.

§Argument
  • callback - A callback which is called with the following parameters as soon as code lenses are requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document for which code actions are requested.
    • return - A list of code lenses to display.
Source

pub fn on_resolve_code_lens( &mut self, callback: fn(&mut Server<T>, CodeLens<T::Command, T::CodeLensData>) -> CodeLens<T::Command, T::CodeLensData>, )

Sets the callback that will be called to compute commands of code lenses, which were previously returned by Server::on_code_lens.

§Argument
  • callback - A callback which is called with the following parameters as soon a code lens can be resolved:
    • The server instance receiving the response.
    • The CodeLens to resolve with command set to None.
    • return - The resolved code lens.
Source§

impl<T: TypeProvider> Server<T>

Sets the callback that will be called to compute document links.

§Argument
  • callback - A callback which is called with the following parameters as soon as links is requested:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the document that has been opened.
    • return - A list of links to display.

Sets the callback that will be called to compute missing information on document links, which were previously returned by Server::on_document_link.

§Argument
  • callback - A callback which is called with the following parameters as soon a link can be resolved:
    • The server instance receiving the response.
    • The DocumentLink to resolve.
    • return - The resolved link.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_rename( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer, Position, String) -> WorkspaceEdit, )

Sets the callback that will be called to rename symbols.

§Argument
  • callback - A callback which is called with the following parameters as soon as a symbol is renamed:
    • The server instance receiving the response.
    • The TextDocumentIdentifer of the target document.
    • The Position of the cursor.
    • The new name of the symbol.
    • return - A WorkspaceEdit that contains the changes to apply to the workspace.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn set_document_sync(&mut self, sync_kind: TextDocumentSyncKind)

Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_show_message_response( &mut self, callback: fn(&mut Server<T>, MessageActionItem<T::ShowMessageRequestData>), )

Set the response handler for showing a message request

§Argument
  • callback - A callback which is called with the following parameters if the result of a query is received:
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_change_configuration( &mut self, callback: fn(&mut Server<T>, T::Configuration), )

Set the request handler for changing the server configuration

§Argument
  • callback - A callback which is called with the following parameters if a change in configuration is received:
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_change_watched_files( &mut self, callback: fn(&mut Server<T>, Vec<FileEvent>), )

Sets the callback that will be called when watched files are changed.

§Argument
  • callback - A callback which is called with the following parameters as soon as watch file changes are received:
    • The server instance receiving the response.
    • A vector of FileEvents.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_symbol( &mut self, callback: fn(&mut Server<T>, String) -> Vec<SymbolInformation>, )

Sets the callback that will be used to resolve symbols in a workspace.

§Argument
  • callback - A callback which is called with the following parameters as soon as the corresponding request is received:
    • The server instance receiving the response.
    • A possibly empty query string that is used to filter the symbols.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_execute_command<R: 'static + Serialize>( &mut self, callback: fn(&mut Server<T>, T::Command) -> R, )

Sets the callback that will be called to execute a command.

§Argument
  • callback - A callback which is called with the following parameters as soon as the corresponding request is received:
    • The server instance receiving the response.
    • The Command to be executed.
Source§

impl<T: TypeProvider> Server<T>

Source

pub fn on_apply_edit_response( &mut self, callback: fn(&mut Server<T>, T::ApplyEditData, ApplyWorkspaceEditResponse), )

Set the response handler for applying a workspace edit

§Argument
  • callback - A callback which is called with the following parameters as soon as a response from Connection::apply_edit is received:
    • The server instance receiving the response.
    • A tag of type TypeProvider::ApplyEditData that was passed to the request.
    • The response data of the client.

Trait Implementations§

Source§

impl<T: TypeProvider> Deref for Server<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: TypeProvider> DerefMut for Server<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T> !Freeze for Server<T>

§

impl<T> !RefUnwindSafe for Server<T>

§

impl<T> !Send for Server<T>

§

impl<T> !Sync for Server<T>

§

impl<T> Unpin for Server<T>

§

impl<T> !UnwindSafe for Server<T>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.