From b042faeb64d858c26b05dbf543925bf626454282 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jul 2019 13:47:02 +0300 Subject: simplify --- crates/ra_lsp_server/src/conv.rs | 13 +++++++++++ crates/ra_lsp_server/src/main_loop/handlers.rs | 30 ++++++-------------------- 2 files changed, 20 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index fc01b1c0e..d0bdc94aa 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -412,6 +412,19 @@ impl TryConvWith for (FileId, RangeInfo) { } } +impl TryConvWith for (FileId, RangeInfo>) { + type Ctx = WorldSnapshot; + type Output = req::GotoDefinitionResponse; + fn try_conv_with(self, world: &WorldSnapshot) -> Result { + let (file_id, RangeInfo { range, info: navs }) = self; + let links = navs + .into_iter() + .map(|nav| (file_id, RangeInfo::new(range, nav))) + .try_conv_with_to_vec(world)?; + Ok(links.into()) + } +} + pub fn to_location( file_id: FileId, range: TextRange, diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 8f07f5027..ab9ed5080 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -9,8 +9,7 @@ use lsp_types::{ TextDocumentIdentifier, TextEdit, WorkspaceEdit, }; use ra_ide_api::{ - AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, - RunnableKind, Severity, + AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, }; use ra_prof::profile; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; @@ -267,13 +266,8 @@ pub fn handle_goto_definition( None => return Ok(None), Some(it) => it, }; - let nav_range = nav_info.range; - let res = nav_info - .info - .into_iter() - .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) - .try_conv_with_to_vec(&world)?; - Ok(Some(res.into())) + let res = (position.file_id, nav_info).try_conv_with(&world)?; + Ok(Some(res)) } pub fn handle_goto_implementation( @@ -285,13 +279,8 @@ pub fn handle_goto_implementation( None => return Ok(None), Some(it) => it, }; - let nav_range = nav_info.range; - let res = nav_info - .info - .into_iter() - .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) - .try_conv_with_to_vec(&world)?; - Ok(Some(res.into())) + let res = (position.file_id, nav_info).try_conv_with(&world)?; + Ok(Some(res)) } pub fn handle_goto_type_definition( @@ -303,13 +292,8 @@ pub fn handle_goto_type_definition( None => return Ok(None), Some(it) => it, }; - let nav_range = nav_info.range; - let res = nav_info - .info - .into_iter() - .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) - .try_conv_with_to_vec(&world)?; - Ok(Some(res.into())) + let res = (position.file_id, nav_info).try_conv_with(&world)?; + Ok(Some(res)) } pub fn handle_parent_module( -- cgit v1.2.3