diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 10e271376..307082865 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -18,7 +18,7 @@ use serde_json::to_value; | |||
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | cargo_target_spec::{runnable_args, CargoTargetSpec}, | 20 | cargo_target_spec::{runnable_args, CargoTargetSpec}, |
21 | conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec}, | 21 | conv::{to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith, TryConvWithToVec}, |
22 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, | 22 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, |
23 | world::WorldSnapshot, | 23 | world::WorldSnapshot, |
24 | LspError, Result, | 24 | LspError, Result, |
@@ -383,8 +383,14 @@ pub fn handle_folding_range( | |||
383 | ) -> Result<Option<Vec<FoldingRange>>> { | 383 | ) -> Result<Option<Vec<FoldingRange>>> { |
384 | let file_id = params.text_document.try_conv_with(&world)?; | 384 | let file_id = params.text_document.try_conv_with(&world)?; |
385 | let folds = world.analysis().folding_ranges(file_id)?; | 385 | let folds = world.analysis().folding_ranges(file_id)?; |
386 | let text = world.analysis().file_text(file_id)?; | ||
386 | let line_index = world.analysis().file_line_index(file_id)?; | 387 | let line_index = world.analysis().file_line_index(file_id)?; |
387 | let res = Some(folds.into_iter().map_conv_with(&*line_index).collect()); | 388 | let ctx = FoldConvCtx { |
389 | text: &text, | ||
390 | line_index: &line_index, | ||
391 | line_folding_only: world.options.line_folding_only, | ||
392 | }; | ||
393 | let res = Some(folds.into_iter().map_conv_with(&ctx).collect()); | ||
388 | Ok(res) | 394 | Ok(res) |
389 | } | 395 | } |
390 | 396 | ||
@@ -475,7 +481,6 @@ pub fn handle_references( | |||
475 | params: req::ReferenceParams, | 481 | params: req::ReferenceParams, |
476 | ) -> Result<Option<Vec<Location>>> { | 482 | ) -> Result<Option<Vec<Location>>> { |
477 | let position = params.text_document_position.try_conv_with(&world)?; | 483 | let position = params.text_document_position.try_conv_with(&world)?; |
478 | let line_index = world.analysis().file_line_index(position.file_id)?; | ||
479 | 484 | ||
480 | let refs = match world.analysis().find_all_refs(position)? { | 485 | let refs = match world.analysis().find_all_refs(position)? { |
481 | None => return Ok(None), | 486 | None => return Ok(None), |
@@ -484,13 +489,19 @@ pub fn handle_references( | |||
484 | 489 | ||
485 | let locations = if params.context.include_declaration { | 490 | let locations = if params.context.include_declaration { |
486 | refs.into_iter() | 491 | refs.into_iter() |
487 | .filter_map(|r| to_location(r.file_id, r.range, &world, &line_index).ok()) | 492 | .filter_map(|r| { |
493 | let line_index = world.analysis().file_line_index(r.file_id).ok()?; | ||
494 | to_location(r.file_id, r.range, &world, &line_index).ok() | ||
495 | }) | ||
488 | .collect() | 496 | .collect() |
489 | } else { | 497 | } else { |
490 | // Only iterate over the references if include_declaration was false | 498 | // Only iterate over the references if include_declaration was false |
491 | refs.references() | 499 | refs.references() |
492 | .iter() | 500 | .iter() |
493 | .filter_map(|r| to_location(r.file_id, r.range, &world, &line_index).ok()) | 501 | .filter_map(|r| { |
502 | let line_index = world.analysis().file_line_index(r.file_id).ok()?; | ||
503 | to_location(r.file_id, r.range, &world, &line_index).ok() | ||
504 | }) | ||
494 | .collect() | 505 | .collect() |
495 | }; | 506 | }; |
496 | 507 | ||
@@ -740,6 +751,7 @@ pub fn handle_document_highlight( | |||
740 | 751 | ||
741 | Ok(Some( | 752 | Ok(Some( |
742 | refs.into_iter() | 753 | refs.into_iter() |
754 | .filter(|r| r.file_id == file_id) | ||
743 | .map(|r| DocumentHighlight { range: r.range.conv_with(&line_index), kind: None }) | 755 | .map(|r| DocumentHighlight { range: r.range.conv_with(&line_index), kind: None }) |
744 | .collect(), | 756 | .collect(), |
745 | )) | 757 | )) |