aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs70
1 files changed, 42 insertions, 28 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index ea947417f..1077aafd8 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,7 +9,8 @@ use lsp_types::{
9 TextDocumentIdentifier, TextEdit, WorkspaceEdit, 9 TextDocumentIdentifier, TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, 12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, InlayKind, Query,
13 RunnableKind, Severity,
13}; 14};
14use ra_prof::profile; 15use ra_prof::profile;
15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 16use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -685,13 +686,14 @@ pub fn handle_code_lens(
685 params: req::CodeLensParams, 686 params: req::CodeLensParams,
686) -> Result<Option<Vec<CodeLens>>> { 687) -> Result<Option<Vec<CodeLens>>> {
687 let file_id = params.text_document.try_conv_with(&world)?; 688 let file_id = params.text_document.try_conv_with(&world)?;
688 let line_index = world.analysis().file_line_index(file_id); 689 let analysis = world.analysis();
690 let line_index = analysis.file_line_index(file_id);
689 691
690 let mut lenses: Vec<CodeLens> = Default::default(); 692 let mut lenses: Vec<CodeLens> = Default::default();
691 let workspace_root = world.workspace_root_for(file_id); 693 let workspace_root = world.workspace_root_for(file_id);
692 694
693 // Gather runnables 695 // Gather runnables
694 for runnable in world.analysis().runnables(file_id)? { 696 for runnable in analysis.runnables(file_id)? {
695 let title = match &runnable.kind { 697 let title = match &runnable.kind {
696 RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"), 698 RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"),
697 RunnableKind::Bench { .. } => Some("Run Bench"), 699 RunnableKind::Bench { .. } => Some("Run Bench"),
@@ -726,39 +728,51 @@ pub fn handle_code_lens(
726 } 728 }
727 } 729 }
728 730
729 lenses.extend(world.analysis().file_structure(file_id).into_iter().filter_map(|it| { 731 // Handle impls
730 match it.kind { 732 lenses.extend(
731 // Handle impls 733 analysis
732 SyntaxKind::TRAIT_DEF | SyntaxKind::STRUCT_DEF | SyntaxKind::ENUM_DEF => { 734 .file_structure(file_id)
735 .into_iter()
736 .filter(|it| match it.kind {
737 SyntaxKind::TRAIT_DEF | SyntaxKind::STRUCT_DEF | SyntaxKind::ENUM_DEF => true,
738 _ => false,
739 })
740 .map(|it| {
733 let range = it.node_range.conv_with(&line_index); 741 let range = it.node_range.conv_with(&line_index);
734 let pos = range.start; 742 let pos = range.start;
735 let lens_params = 743 let lens_params =
736 req::TextDocumentPositionParams::new(params.text_document.clone(), pos); 744 req::TextDocumentPositionParams::new(params.text_document.clone(), pos);
737 Some(CodeLens { 745 CodeLens {
738 range, 746 range,
739 command: None, 747 command: None,
740 data: Some(to_value(CodeLensResolveData::Impls(lens_params)).unwrap()), 748 data: Some(to_value(CodeLensResolveData::Impls(lens_params)).unwrap()),
741 }) 749 }
742 } 750 }),
743 // handle let statements 751 );
744 SyntaxKind::LET_STMT => world 752
745 .analysis() 753 lenses.extend(
746 .type_of(FileRange { range: it.navigation_range, file_id }) 754 analysis
747 .ok() 755 .inlay_hints(file_id)
748 .and_then(std::convert::identity) 756 .into_iter()
749 .filter(|resolved_type| "{unknown}" != resolved_type) 757 .filter(|hint| hint.inlay_kind == InlayKind::LetBinding)
750 .map(|resolved_type| CodeLens { 758 .filter_map(|inlay_hint| {
751 range: it.node_range.conv_with(&line_index), 759 let resolved_type = analysis
752 command: Some(Command { 760 .type_of(FileRange { range: inlay_hint.range, file_id })
753 title: resolved_type, 761 .ok()
754 command: String::new(), 762 .and_then(std::convert::identity)
755 arguments: None, 763 .filter(|resolved_type| "{unknown}" != resolved_type);
756 }), 764 resolved_type.map(|resolved_type| (resolved_type, inlay_hint.range))
757 data: None, 765 })
766 .map(|(resolved_type, range)| CodeLens {
767 range: range.conv_with(&line_index),
768 command: Some(Command {
769 title: resolved_type,
770 command: String::new(),
771 arguments: None,
758 }), 772 }),
759 _ => None, 773 data: None,
760 } 774 }),
761 })); 775 );
762 Ok(Some(lenses)) 776 Ok(Some(lenses))
763} 777}
764 778