From 227bc0b6d478564c45f49cb47dac963d9c37a528 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jul 2019 13:39:16 +0300 Subject: add try_conv_with_to_vec --- crates/ra_lsp_server/src/main_loop/handlers.rs | 27 ++++++++------------------ 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 62c8cbf71..8f07f5027 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -21,7 +21,7 @@ use url_serde::Ser; use crate::{ cargo_target_spec::{runnable_args, CargoTargetSpec}, - conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, + conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec}, req::{self, Decoration}, world::WorldSnapshot, LspError, Result, @@ -263,7 +263,6 @@ pub fn handle_goto_definition( 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_definition(position)? { None => return Ok(None), Some(it) => it, @@ -272,9 +271,8 @@ pub fn handle_goto_definition( let res = nav_info .info .into_iter() - .map(|nav| RangeInfo::new(nav_range, nav)) - .map(|nav| to_location_link(&nav, &world, &line_index)) - .collect::>>()?; + .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) + .try_conv_with_to_vec(&world)?; Ok(Some(res.into())) } @@ -283,7 +281,6 @@ pub fn handle_goto_implementation( 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, @@ -292,9 +289,8 @@ pub fn handle_goto_implementation( let res = nav_info .info .into_iter() - .map(|nav| RangeInfo::new(nav_range, nav)) - .map(|nav| to_location_link(&nav, &world, &line_index)) - .collect::>>()?; + .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) + .try_conv_with_to_vec(&world)?; Ok(Some(res.into())) } @@ -303,7 +299,6 @@ pub fn handle_goto_type_definition( 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, @@ -312,9 +307,8 @@ pub fn handle_goto_type_definition( let res = nav_info .info .into_iter() - .map(|nav| RangeInfo::new(nav_range, nav)) - .map(|nav| to_location_link(&nav, &world, &line_index)) - .collect::>>()?; + .map(|nav| (position.file_id, RangeInfo::new(nav_range, nav))) + .try_conv_with_to_vec(&world)?; Ok(Some(res.into())) } @@ -323,12 +317,7 @@ pub fn handle_parent_module( params: req::TextDocumentPositionParams, ) -> Result> { let position = params.try_conv_with(&world)?; - world - .analysis() - .parent_module(position)? - .into_iter() - .map(|nav| nav.try_conv_with(&world)) - .collect::>>() + world.analysis().parent_module(position)?.iter().try_conv_with_to_vec(&world) } pub fn handle_runnables( -- cgit v1.2.3 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/main_loop/handlers.rs | 30 ++++++-------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs') 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