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>
impl<T: TypeProvider> Server<T>
Sourcepub fn new(state: T, transport: Transport) -> Server<T>
pub fn new(state: T, transport: Transport) -> Server<T>
Creates a new server with the given state and transport.
Sourcepub fn process_id(&self) -> Option<u32>
pub fn process_id(&self) -> Option<u32>
Returns the process id of the server, if one is provided by the client.
Sourcepub fn root_uri(&self) -> Option<&str>
pub fn root_uri(&self) -> Option<&str>
Returns the root uri of the workspace, if one is provided by the client.
Sourcepub fn initialization_options(&self) -> Option<&T::InitializeOptions>
pub fn initialization_options(&self) -> Option<&T::InitializeOptions>
Returns the initialization options as defined in TypeProvider::InitializeOptions if available and parsed correctly.
Sourcepub fn split(&mut self) -> (&mut Connection<T>, &mut T)
pub fn split(&mut self) -> (&mut Connection<T>, &mut T)
Splits the server into its connection and state.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_open(&mut self, callback: fn(&mut Server<T>, TextDocumentItem))
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
TextDocumentItemof the document that has been opened.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_change(
&mut self,
callback: fn(&mut Server<T>, VersionedTextDocumentIdentifier, Vec<TextDocumentContentChangeEvent>),
)
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
callback- A callback which is called with the following parameters as soon as a change is detected:- The server instance receiving the response.
- The
VersionedTextDocumentIdentifierof the document that changed. - The
Vec<TextDocumentContentChangeEvent>that contains the changes to the document.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_will_save(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, TextDocumentSaveReason),
)
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:- The server instance receiving the response.
- The
TextDocumentIdentiferof the target document. - The
TextDocumentSaveReasonthat specifies why the document is saved.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_will_save_wait_until(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, TextDocumentSaveReason) -> Vec<TextEdit>,
)
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
TextDocumentIdentiferof the target document. - The
TextDocumentSaveReasonthat specifies why the document is saved. return- A list of edits to apply to the document.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_save(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Option<String>),
)
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:- The server instance receiving the response.
- The
TextDocumentIdentiferof the saved document. - The content of the file, if enabled via
Server::set_save_include_text.
Sourcepub fn set_save_include_text(&mut self, value: bool)
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- Iftrue, the content of the file will be included in the callback.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_close(&mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer))
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
TextDocumentIdentiferof the document that has been closed.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_completion(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> CompletionList<T>,
)
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
TextDocumentIdentiferof the document for which completions are requested. return- A list of completions to display.
Sourcepub fn on_resolve_completion(
&mut self,
callback: fn(&mut Server<T>, CompletionItem<T>) -> CompletionItem<T>,
)
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
CompletionItemto resolve. return- The resolved completion.
Sourcepub fn set_completion_trigger_character(
&mut self,
trigger_characters: Vec<String>,
)
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.
Sourcepub fn snippet_support(&self) -> bool
pub fn snippet_support(&self) -> bool
Returns whether the client supports snippets for completion items.
§Return
trueif the client supports snippets,falseotherwise.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_hover(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Hover,
)
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
TextDocumentIdentiferof the target document. - The
Positionof the cursor. return- The hover information to display.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_signature_help(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> SignatureHelp,
)
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
TextDocumentIdentiferof the target document. - The
Positionof the cursor. return- The signature help to display.
Sourcepub fn set_signature_help_trigger_characters(&mut self, value: Vec<String>)
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>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_references(
&mut self,
callback: fn(_: &mut Server<T>, _: TextDocumentIdentifer, _: Position, context: ReferenceContext) -> Vec<Location>,
)
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
TextDocumentIdentiferof the target document. - The
Positionof the cursor. - The
ReferenceContextthat 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>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_document_highlight(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Vec<DocumentHighlight>,
)
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
TextDocumentIdentiferof the target document. - The
Positionof the cursor. return- A list of highlights to display.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_document_symbol(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<SymbolInformation>,
)
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
TextDocumentIdentiferof the target document. return- A list of symbols to display.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_formatting(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, FormattingOptions) -> Vec<TextEdit>,
)
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- TheTextDocumentIdentiferof the target document.options- TheFormattingOptionsthat specify how the document should be formatted.return- A list of edits to apply to the document.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_range_formatting(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Range, FormattingOptions) -> Vec<TextEdit>,
)
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- TheTextDocumentIdentiferof the target document.range- TheRangethat should be formatted.options- TheFormattingOptionsthat specify how the document should be formatted.return- A list of edits to apply to the document.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_type_formatting(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position, String, FormattingOptions) -> Vec<TextEdit>,
)
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- TheTextDocumentIdentiferof the target document.position- ThePositionof the cursor.options- TheFormattingOptionsthat specify how the document should be formatted.return- A list of edits to apply to the document.
Sourcepub fn set_on_type_formatting_first_trigger_character(&mut self, value: String)
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.
Sourcepub fn set_on_type_formatting_more_trigger_characters(
&mut self,
value: Vec<String>,
)
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>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_definition(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position) -> Vec<Location>,
)
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
TextDocumentIdentiferof the document for which a definition is requested. - The
Positionat which a definition is requested. return- A list ofLocations to display.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_code_action(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Range, CodeActionContext) -> Vec<T::Command>,
)
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
TextDocumentIdentiferof the document for which code actions are requested. - The
Rangeof the document for which code actions are requested. - The
CodeActionContextfor which code actions are requested. return- A list of commands to execute.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_code_lens(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<CodeLens<T::Command, T::CodeLensData>>,
)
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
TextDocumentIdentiferof the document for which code actions are requested. return- A list of code lenses to display.
Sourcepub fn on_resolve_code_lens(
&mut self,
callback: fn(&mut Server<T>, CodeLens<T::Command, T::CodeLensData>) -> CodeLens<T::Command, T::CodeLensData>,
)
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
CodeLensto resolve withcommandset toNone. return- The resolved code lens.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_document_link(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<DocumentLink>,
)
pub fn on_document_link( &mut self, callback: fn(&mut Server<T>, TextDocumentIdentifer) -> Vec<DocumentLink>, )
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
TextDocumentIdentiferof the document that has been opened. return- A list of links to display.
Sourcepub fn on_document_link_resolve(
&mut self,
callback: fn(&mut Server<T>, DocumentLink) -> DocumentLink,
)
pub fn on_document_link_resolve( &mut self, callback: fn(&mut Server<T>, DocumentLink) -> DocumentLink, )
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
DocumentLinkto resolve. return- The resolved link.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_rename(
&mut self,
callback: fn(&mut Server<T>, TextDocumentIdentifer, Position, String) -> WorkspaceEdit,
)
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
TextDocumentIdentiferof the target document. - The
Positionof the cursor. - The new name of the symbol.
return- AWorkspaceEditthat contains the changes to apply to the workspace.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
pub fn set_document_sync(&mut self, sync_kind: TextDocumentSyncKind)
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_show_message_response(
&mut self,
callback: fn(&mut Server<T>, MessageActionItem<T::ShowMessageRequestData>),
)
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:- The server instance receiving the response.
- A tag of type
TypeProvider::ShowMessageRequestDatathat was passed to the request.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_change_configuration(
&mut self,
callback: fn(&mut Server<T>, T::Configuration),
)
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:- The server instance receiving the response.
- The updated configuration of type
TypeProvider::Configuration.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_change_watched_files(
&mut self,
callback: fn(&mut Server<T>, Vec<FileEvent>),
)
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>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_symbol(
&mut self,
callback: fn(&mut Server<T>, String) -> Vec<SymbolInformation>,
)
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>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_execute_command<R: 'static + Serialize>(
&mut self,
callback: fn(&mut Server<T>, T::Command) -> R,
)
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
Commandto be executed.
Source§impl<T: TypeProvider> Server<T>
impl<T: TypeProvider> Server<T>
Sourcepub fn on_apply_edit_response(
&mut self,
callback: fn(&mut Server<T>, T::ApplyEditData, ApplyWorkspaceEditResponse),
)
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 fromConnection::apply_editis received:- The server instance receiving the response.
- A tag of type
TypeProvider::ApplyEditDatathat was passed to the request. - The response data of the client.