aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2019-07-19 06:53:12 +0100
committerKirill Bulatov <[email protected]>2019-07-20 19:39:04 +0100
commitb6c662c573014710d4e8d9fd9253793141d8bbe0 (patch)
tree2b680a1c7c50125ed6a90d8de20d9d15460349b4 /crates/ra_lsp_server
parent7bde8012cb28c44de7ffc779003781d385323808 (diff)
If possible, show type lenses for the let bindings
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs42
1 files changed, 26 insertions, 16 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 68865b755..ea947417f 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -726,29 +726,39 @@ pub fn handle_code_lens(
726 } 726 }
727 } 727 }
728 728
729 // Handle impls 729 lenses.extend(world.analysis().file_structure(file_id).into_iter().filter_map(|it| {
730 lenses.extend( 730 match it.kind {
731 world 731 // Handle impls
732 .analysis() 732 SyntaxKind::TRAIT_DEF | SyntaxKind::STRUCT_DEF | SyntaxKind::ENUM_DEF => {
733 .file_structure(file_id)
734 .into_iter()
735 .filter(|it| match it.kind {
736 SyntaxKind::TRAIT_DEF | SyntaxKind::STRUCT_DEF | SyntaxKind::ENUM_DEF => true,
737 _ => false,
738 })
739 .map(|it| {
740 let range = it.node_range.conv_with(&line_index); 733 let range = it.node_range.conv_with(&line_index);
741 let pos = range.start; 734 let pos = range.start;
742 let lens_params = 735 let lens_params =
743 req::TextDocumentPositionParams::new(params.text_document.clone(), pos); 736 req::TextDocumentPositionParams::new(params.text_document.clone(), pos);
744 CodeLens { 737 Some(CodeLens {
745 range, 738 range,
746 command: None, 739 command: None,
747 data: Some(to_value(CodeLensResolveData::Impls(lens_params)).unwrap()), 740 data: Some(to_value(CodeLensResolveData::Impls(lens_params)).unwrap()),
748 } 741 })
749 }), 742 }
750 ); 743 // handle let statements
751 744 SyntaxKind::LET_STMT => world
745 .analysis()
746 .type_of(FileRange { range: it.navigation_range, file_id })
747 .ok()
748 .and_then(std::convert::identity)
749 .filter(|resolved_type| "{unknown}" != resolved_type)
750 .map(|resolved_type| CodeLens {
751 range: it.node_range.conv_with(&line_index),
752 command: Some(Command {
753 title: resolved_type,
754 command: String::new(),
755 arguments: None,
756 }),
757 data: None,
758 }),
759 _ => None,
760 }
761 }));
752 Ok(Some(lenses)) 762 Ok(Some(lenses))
753} 763}
754 764