@@ -9,8 +9,7 @@ use lsp_types::{
99 TextDocumentIdentifier , TextEdit , WorkspaceEdit ,
1010} ;
1111use ra_ide_api:: {
12- AssistId , Cancelable , FileId , FilePosition , FileRange , FoldKind , Query , RangeInfo ,
13- RunnableKind , Severity ,
12+ AssistId , Cancelable , FileId , FilePosition , FileRange , FoldKind , Query , RunnableKind , Severity ,
1413} ;
1514use ra_prof:: profile;
1615use ra_syntax:: { AstNode , SyntaxKind , TextRange , TextUnit } ;
@@ -21,7 +20,7 @@ use url_serde::Ser;
2120
2221use crate :: {
2322 cargo_target_spec:: { runnable_args, CargoTargetSpec } ,
24- conv:: { to_location, to_location_link , Conv , ConvWith , MapConvWith , TryConvWith } ,
23+ conv:: { to_location, Conv , ConvWith , MapConvWith , TryConvWith , TryConvWithToVec } ,
2524 req:: { self , Decoration } ,
2625 world:: WorldSnapshot ,
2726 LspError , Result ,
@@ -263,72 +262,46 @@ pub fn handle_goto_definition(
263262 params : req:: TextDocumentPositionParams ,
264263) -> Result < Option < req:: GotoDefinitionResponse > > {
265264 let position = params. try_conv_with ( & world) ?;
266- let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ;
267265 let nav_info = match world. analysis ( ) . goto_definition ( position) ? {
268266 None => return Ok ( None ) ,
269267 Some ( it) => it,
270268 } ;
271- let nav_range = nav_info. range ;
272- let res = nav_info
273- . info
274- . into_iter ( )
275- . map ( |nav| RangeInfo :: new ( nav_range, nav) )
276- . map ( |nav| to_location_link ( & nav, & world, & line_index) )
277- . collect :: < Result < Vec < _ > > > ( ) ?;
278- Ok ( Some ( res. into ( ) ) )
269+ let res = ( position. file_id , nav_info) . try_conv_with ( & world) ?;
270+ Ok ( Some ( res) )
279271}
280272
281273pub fn handle_goto_implementation (
282274 world : WorldSnapshot ,
283275 params : req:: TextDocumentPositionParams ,
284276) -> Result < Option < req:: GotoImplementationResponse > > {
285277 let position = params. try_conv_with ( & world) ?;
286- let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ;
287278 let nav_info = match world. analysis ( ) . goto_implementation ( position) ? {
288279 None => return Ok ( None ) ,
289280 Some ( it) => it,
290281 } ;
291- let nav_range = nav_info. range ;
292- let res = nav_info
293- . info
294- . into_iter ( )
295- . map ( |nav| RangeInfo :: new ( nav_range, nav) )
296- . map ( |nav| to_location_link ( & nav, & world, & line_index) )
297- . collect :: < Result < Vec < _ > > > ( ) ?;
298- Ok ( Some ( res. into ( ) ) )
282+ let res = ( position. file_id , nav_info) . try_conv_with ( & world) ?;
283+ Ok ( Some ( res) )
299284}
300285
301286pub fn handle_goto_type_definition (
302287 world : WorldSnapshot ,
303288 params : req:: TextDocumentPositionParams ,
304289) -> Result < Option < req:: GotoTypeDefinitionResponse > > {
305290 let position = params. try_conv_with ( & world) ?;
306- let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ;
307291 let nav_info = match world. analysis ( ) . goto_type_definition ( position) ? {
308292 None => return Ok ( None ) ,
309293 Some ( it) => it,
310294 } ;
311- let nav_range = nav_info. range ;
312- let res = nav_info
313- . info
314- . into_iter ( )
315- . map ( |nav| RangeInfo :: new ( nav_range, nav) )
316- . map ( |nav| to_location_link ( & nav, & world, & line_index) )
317- . collect :: < Result < Vec < _ > > > ( ) ?;
318- Ok ( Some ( res. into ( ) ) )
295+ let res = ( position. file_id , nav_info) . try_conv_with ( & world) ?;
296+ Ok ( Some ( res) )
319297}
320298
321299pub fn handle_parent_module (
322300 world : WorldSnapshot ,
323301 params : req:: TextDocumentPositionParams ,
324302) -> Result < Vec < Location > > {
325303 let position = params. try_conv_with ( & world) ?;
326- world
327- . analysis ( )
328- . parent_module ( position) ?
329- . into_iter ( )
330- . map ( |nav| nav. try_conv_with ( & world) )
331- . collect :: < Result < Vec < _ > > > ( )
304+ world. analysis ( ) . parent_module ( position) ?. iter ( ) . try_conv_with_to_vec ( & world)
332305}
333306
334307pub fn handle_runnables (
0 commit comments