From 7125192c1e46f2350707c4903a1679b2a0178ea6 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 23 Apr 2019 14:11:27 -0400 Subject: Basic resolution for ADT --- 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 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index f6d2b75e7..9095bee89 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, ImplementationProviderCapability, GenericCapability, + TextDocumentSyncOptions, ImplementationProviderCapability, GenericCapability, TypeDefinitionProviderCapability }; pub fn server_capabilities() -> ServerCapabilities { @@ -23,7 +23,7 @@ pub fn server_capabilities() -> ServerCapabilities { trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]), }), definition_provider: Some(true), - type_definition_provider: None, + type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)), implementation_provider: Some(ImplementationProviderCapability::Simple(true)), references_provider: Some(true), document_highlight_provider: Some(true), diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index dc1f8f3f7..87b4e3ac2 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -306,6 +306,7 @@ fn on_request( .on::(handlers::handle_workspace_symbol)? .on::(handlers::handle_goto_definition)? .on::(handlers::handle_goto_implementation)? + .on::(handlers::handle_goto_type_definition)? .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 530081494..23802e5e1 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -288,6 +288,26 @@ pub fn handle_goto_implementation( Ok(Some(req::GotoDefinitionResponse::Link(res))) } +pub fn handle_goto_type_definition( + 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_type_definition(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, -- cgit v1.2.3