pub struct Translator { /* private fields */ }Expand description
Translator handles MCP tool calls by converting them to LSP requests.
Implementations§
Source§impl Translator
impl Translator
Sourcepub fn set_workspace_roots(&mut self, roots: Vec<PathBuf>)
pub fn set_workspace_roots(&mut self, roots: Vec<PathBuf>)
Set the workspace roots for path validation.
Sourcepub fn set_expected_languages(&mut self, languages: HashSet<String>)
pub fn set_expected_languages(&mut self, languages: HashSet<String>)
Mark the set of languages whose LSP servers are expected (configured + applicable) but may still be initializing in the background.
Sourcepub fn clear_expected_languages(&mut self)
pub fn clear_expected_languages(&mut self)
Clear the expected-languages set (e.g. after background init failed).
Sourcepub fn with_extensions(self, extension_map: HashMap<String, String>) -> Self
pub fn with_extensions(self, extension_map: HashMap<String, String>) -> Self
Configure custom file extension mappings.
This method sets the extension map and updates the document tracker to use the same mappings for language detection.
Sourcepub fn register_client(&mut self, language_id: String, client: LspClient)
pub fn register_client(&mut self, language_id: String, client: LspClient)
Register an LSP client for a language.
Sourcepub fn register_server(&mut self, language_id: String, server: LspServer)
pub fn register_server(&mut self, language_id: String, server: LspServer)
Register an LSP server for a language.
Sourcepub const fn document_tracker(&self) -> &DocumentTracker
pub const fn document_tracker(&self) -> &DocumentTracker
Get the document tracker.
Sourcepub const fn document_tracker_mut(&mut self) -> &mut DocumentTracker
pub const fn document_tracker_mut(&mut self) -> &mut DocumentTracker
Get a mutable reference to the document tracker.
Sourcepub const fn notification_cache(&self) -> &NotificationCache
pub const fn notification_cache(&self) -> &NotificationCache
Get the notification cache.
Sourcepub const fn notification_cache_mut(&mut self) -> &mut NotificationCache
pub const fn notification_cache_mut(&mut self) -> &mut NotificationCache
Get a mutable reference to the notification cache.
Source§impl Translator
impl Translator
Sourcepub async fn handle_hover(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<HoverResult>
pub async fn handle_hover( &mut self, file_path: String, line: u32, character: u32, ) -> Result<HoverResult>
Handle hover request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_definition(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<DefinitionResult>
pub async fn handle_definition( &mut self, file_path: String, line: u32, character: u32, ) -> Result<DefinitionResult>
Handle definition request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_references(
&mut self,
file_path: String,
line: u32,
character: u32,
include_declaration: bool,
) -> Result<ReferencesResult>
pub async fn handle_references( &mut self, file_path: String, line: u32, character: u32, include_declaration: bool, ) -> Result<ReferencesResult>
Handle references request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_diagnostics(
&mut self,
file_path: String,
) -> Result<DiagnosticsResult>
pub async fn handle_diagnostics( &mut self, file_path: String, ) -> Result<DiagnosticsResult>
Handle diagnostics request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_rename(
&mut self,
file_path: String,
line: u32,
character: u32,
new_name: String,
) -> Result<RenameResult>
pub async fn handle_rename( &mut self, file_path: String, line: u32, character: u32, new_name: String, ) -> Result<RenameResult>
Handle rename request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_completions(
&mut self,
file_path: String,
line: u32,
character: u32,
trigger: Option<String>,
) -> Result<CompletionsResult>
pub async fn handle_completions( &mut self, file_path: String, line: u32, character: u32, trigger: Option<String>, ) -> Result<CompletionsResult>
Handle completions request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_document_symbols(
&mut self,
file_path: String,
) -> Result<DocumentSymbolsResult>
pub async fn handle_document_symbols( &mut self, file_path: String, ) -> Result<DocumentSymbolsResult>
Handle document symbols request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_format_document(
&mut self,
file_path: String,
tab_size: u32,
insert_spaces: bool,
) -> Result<FormatDocumentResult>
pub async fn handle_format_document( &mut self, file_path: String, tab_size: u32, insert_spaces: bool, ) -> Result<FormatDocumentResult>
Handle format document request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_workspace_symbol(
&mut self,
query: String,
kind_filter: Option<String>,
limit: u32,
) -> Result<WorkspaceSymbolResult>
pub async fn handle_workspace_symbol( &mut self, query: String, kind_filter: Option<String>, limit: u32, ) -> Result<WorkspaceSymbolResult>
Handle workspace symbol search.
§Errors
Returns an error if the LSP request fails or no server is configured.
Sourcepub async fn handle_code_actions(
&mut self,
file_path: String,
start_line: u32,
start_character: u32,
end_line: u32,
end_character: u32,
kind_filter: Option<String>,
) -> Result<CodeActionsResult>
pub async fn handle_code_actions( &mut self, file_path: String, start_line: u32, start_character: u32, end_line: u32, end_character: u32, kind_filter: Option<String>, ) -> Result<CodeActionsResult>
Handle code actions request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_call_hierarchy_prepare(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<CallHierarchyPrepareResult>
pub async fn handle_call_hierarchy_prepare( &mut self, file_path: String, line: u32, character: u32, ) -> Result<CallHierarchyPrepareResult>
Handle call hierarchy prepare request.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_incoming_calls(
&mut self,
item: Value,
) -> Result<IncomingCallsResult>
pub async fn handle_incoming_calls( &mut self, item: Value, ) -> Result<IncomingCallsResult>
Handle incoming calls request.
§Errors
Returns an error if the LSP request fails or the item is invalid.
Sourcepub async fn handle_outgoing_calls(
&mut self,
item: Value,
) -> Result<OutgoingCallsResult>
pub async fn handle_outgoing_calls( &mut self, item: Value, ) -> Result<OutgoingCallsResult>
Handle outgoing calls request.
§Errors
Returns an error if the LSP request fails or the item is invalid.
Sourcepub fn handle_cached_diagnostics(
&mut self,
file_path: &str,
) -> Result<DiagnosticsResult>
pub fn handle_cached_diagnostics( &mut self, file_path: &str, ) -> Result<DiagnosticsResult>
Handle cached diagnostics request.
§Errors
Returns an error if the path is invalid or outside workspace boundaries.
Sourcepub fn handle_server_logs(
&mut self,
limit: usize,
min_level: Option<String>,
) -> Result<ServerLogsResult>
pub fn handle_server_logs( &mut self, limit: usize, min_level: Option<String>, ) -> Result<ServerLogsResult>
Sourcepub fn handle_server_messages(
&mut self,
limit: usize,
) -> Result<ServerMessagesResult>
pub fn handle_server_messages( &mut self, limit: usize, ) -> Result<ServerMessagesResult>
Sourcepub async fn handle_signature_help(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<SignatureHelpResult>
pub async fn handle_signature_help( &mut self, file_path: String, line: u32, character: u32, ) -> Result<SignatureHelpResult>
Handle signature help request (textDocument/signatureHelp).
Returns parameter signatures and documentation while typing a function call.
context is omitted (None) — the server infers trigger state from position.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_implementation(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<LocationsResult>
pub async fn handle_implementation( &mut self, file_path: String, line: u32, character: u32, ) -> Result<LocationsResult>
Handle go-to-implementation request (textDocument/implementation).
Returns the locations of trait method or interface member implementations.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_type_definition(
&mut self,
file_path: String,
line: u32,
character: u32,
) -> Result<LocationsResult>
pub async fn handle_type_definition( &mut self, file_path: String, line: u32, character: u32, ) -> Result<LocationsResult>
Handle go-to-type-definition request (textDocument/typeDefinition).
Returns the type definition location of the expression at position. Distinct from go-to-definition for variable bindings where definition and type differ.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.
Sourcepub async fn handle_inlay_hints(
&mut self,
file_path: String,
start_line: u32,
start_character: u32,
end_line: u32,
end_character: u32,
) -> Result<InlayHintsResult>
pub async fn handle_inlay_hints( &mut self, file_path: String, start_line: u32, start_character: u32, end_line: u32, end_character: u32, ) -> Result<InlayHintsResult>
Handle inlay hints request (textDocument/inlayHint).
Returns inferred type and parameter annotations the editor would render inline. Output positions are in MCP 1-based form.
§Errors
Returns an error if the LSP request fails or the file cannot be opened.