diff options
Diffstat (limited to 'crates/ra_lsp_server/src/conv.rs')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 32e67838e..fc01b1c0e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -384,27 +384,32 @@ impl TryConvWith for &NavigationTarget { | |||
384 | } | 384 | } |
385 | } | 385 | } |
386 | 386 | ||
387 | pub fn to_location_link( | 387 | impl TryConvWith for (FileId, RangeInfo<NavigationTarget>) { |
388 | target: &RangeInfo<NavigationTarget>, | 388 | type Ctx = WorldSnapshot; |
389 | world: &WorldSnapshot, | 389 | type Output = LocationLink; |
390 | // line index for original range file | 390 | fn try_conv_with(self, world: &WorldSnapshot) -> Result<LocationLink> { |
391 | line_index: &LineIndex, | 391 | let (src_file_id, target) = self; |
392 | ) -> Result<LocationLink> { | 392 | |
393 | let target_uri = target.info.file_id().try_conv_with(world)?; | 393 | let target_uri = target.info.file_id().try_conv_with(world)?; |
394 | let tgt_line_index = world.analysis().file_line_index(target.info.file_id()); | 394 | let src_line_index = world.analysis().file_line_index(src_file_id); |
395 | 395 | let tgt_line_index = world.analysis().file_line_index(target.info.file_id()); | |
396 | let target_range = target.info.full_range().conv_with(&tgt_line_index); | 396 | |
397 | 397 | let target_range = target.info.full_range().conv_with(&tgt_line_index); | |
398 | let target_selection_range = | 398 | |
399 | target.info.focus_range().map(|it| it.conv_with(&tgt_line_index)).unwrap_or(target_range); | 399 | let target_selection_range = target |
400 | 400 | .info | |
401 | let res = LocationLink { | 401 | .focus_range() |
402 | origin_selection_range: Some(target.range.conv_with(line_index)), | 402 | .map(|it| it.conv_with(&tgt_line_index)) |
403 | target_uri, | 403 | .unwrap_or(target_range); |
404 | target_range, | 404 | |
405 | target_selection_range, | 405 | let res = LocationLink { |
406 | }; | 406 | origin_selection_range: Some(target.range.conv_with(&src_line_index)), |
407 | Ok(res) | 407 | target_uri, |
408 | target_range, | ||
409 | target_selection_range, | ||
410 | }; | ||
411 | Ok(res) | ||
412 | } | ||
408 | } | 413 | } |
409 | 414 | ||
410 | pub fn to_location( | 415 | pub fn to_location( |
@@ -452,3 +457,23 @@ where | |||
452 | self.iter.next().map(|item| item.conv_with(self.ctx)) | 457 | self.iter.next().map(|item| item.conv_with(self.ctx)) |
453 | } | 458 | } |
454 | } | 459 | } |
460 | |||
461 | pub trait TryConvWithToVec<'a>: Sized + 'a { | ||
462 | type Ctx; | ||
463 | type Output; | ||
464 | |||
465 | fn try_conv_with_to_vec(self, ctx: &'a Self::Ctx) -> Result<Vec<Self::Output>>; | ||
466 | } | ||
467 | |||
468 | impl<'a, I> TryConvWithToVec<'a> for I | ||
469 | where | ||
470 | I: Iterator + 'a, | ||
471 | I::Item: TryConvWith, | ||
472 | { | ||
473 | type Ctx = <I::Item as TryConvWith>::Ctx; | ||
474 | type Output = <I::Item as TryConvWith>::Output; | ||
475 | |||
476 | fn try_conv_with_to_vec(self, ctx: &'a Self::Ctx) -> Result<Vec<Self::Output>> { | ||
477 | self.map(|it| it.try_conv_with(ctx)).collect() | ||
478 | } | ||
479 | } | ||