From 3c17643b3085682a695f0e6d80483edc00d04cb3 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Mon, 28 Jan 2019 09:26:32 -0500 Subject: Go to Implementation for structs and enums --- crates/ra_lsp_server/src/caps.rs | 4 ++-- crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 20 ++++++++++++++++++++ crates/ra_lsp_server/src/req.rs | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index bca079d65..254624487 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs @@ -2,7 +2,7 @@ use lsp_types::{ CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, - TextDocumentSyncOptions, + TextDocumentSyncOptions, ImplementationProviderCapability, }; pub fn server_capabilities() -> ServerCapabilities { @@ -26,7 +26,7 @@ pub fn server_capabilities() -> ServerCapabilities { }), definition_provider: Some(true), type_definition_provider: None, - implementation_provider: None, + implementation_provider: Some(ImplementationProviderCapability::Simple(true)), references_provider: Some(true), document_highlight_provider: Some(true), document_symbol_provider: Some(true), diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index e430ac6de..df390c19e 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -305,6 +305,7 @@ fn on_request( .on::(handlers::handle_document_symbol)? .on::(handlers::handle_workspace_symbol)? .on::(handlers::handle_goto_definition)? + .on::(handlers::handle_goto_implementation)? .on::(handlers::handle_parent_module)? .on::(handlers::handle_runnables)? .on::(handlers::handle_decorations)? diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 9478ebfb8..e94d76903 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -229,6 +229,26 @@ pub fn handle_goto_definition( Ok(Some(req::GotoDefinitionResponse::Link(res))) } +pub fn handle_goto_implementation( + world: ServerWorld, + params: req::TextDocumentPositionParams, +) -> Result> { + let position = params.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(position.file_id); + let nav_info = match world.analysis().goto_implementation(position)? { + None => return Ok(None), + Some(it) => it, + }; + let nav_range = nav_info.range; + let res = nav_info + .info + .into_iter() + .map(|nav| RangeInfo::new(nav_range, nav)) + .map(|nav| to_location_link(&nav, &world, &line_index)) + .collect::>>()?; + Ok(Some(req::GotoDefinitionResponse::Link(res))) +} + pub fn handle_parent_module( world: ServerWorld, params: req::TextDocumentPositionParams, diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index a4d890755..e224ede80 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -8,7 +8,7 @@ pub use lsp_types::{ CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, - TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, + TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams }; pub enum AnalyzerStatus {} -- cgit v1.2.3