diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/display/structure.rs | 22 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 42 |
2 files changed, 48 insertions, 16 deletions
diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index 2ba10b2ef..223941688 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use crate::TextRange; | 1 | use crate::TextRange; |
2 | 2 | ||
3 | use ra_syntax::ast::PatKind; | ||
3 | use ra_syntax::{ | 4 | use ra_syntax::{ |
4 | algo::visit::{visitor, Visitor}, | 5 | algo::visit::{visitor, Visitor}, |
5 | ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, | 6 | ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, |
@@ -155,6 +156,27 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
155 | } | 156 | } |
156 | decl(mc) | 157 | decl(mc) |
157 | }) | 158 | }) |
159 | .visit(|let_statement: &ast::LetStmt| { | ||
160 | let let_syntax = let_statement.syntax(); | ||
161 | |||
162 | let mut label = String::new(); | ||
163 | collapse_ws(let_syntax, &mut label); | ||
164 | |||
165 | let pat = match let_statement.pat()?.kind() { | ||
166 | PatKind::BindPat(bind_pat) => bind_pat, | ||
167 | _ => return None, | ||
168 | }; | ||
169 | |||
170 | Some(StructureNode { | ||
171 | parent: None, | ||
172 | label, | ||
173 | navigation_range: pat.syntax().range(), | ||
174 | node_range: let_syntax.range(), | ||
175 | kind: let_syntax.kind(), | ||
176 | detail: None, | ||
177 | deprecated: false, | ||
178 | }) | ||
179 | }) | ||
158 | .accept(&node)? | 180 | .accept(&node)? |
159 | } | 181 | } |
160 | 182 | ||
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 | ||