diff options
Diffstat (limited to 'crates/ra_analysis/src/descriptors/function')
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/imp.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/mod.rs | 29 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/function/scope.rs | 7 |
3 files changed, 20 insertions, 28 deletions
diff --git a/crates/ra_analysis/src/descriptors/function/imp.rs b/crates/ra_analysis/src/descriptors/function/imp.rs index 0a006f733..11fffeefc 100644 --- a/crates/ra_analysis/src/descriptors/function/imp.rs +++ b/crates/ra_analysis/src/descriptors/function/imp.rs | |||
@@ -1,14 +1,10 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::ast::{AstNode, FnDef, FnDefNode}; |
4 | ast::{AstNode, FnDef, FnDefNode}, | ||
5 | }; | ||
6 | 4 | ||
7 | use crate::{ | 5 | use crate::descriptors::{ |
8 | descriptors::{ | 6 | function::{FnId, FnScopes}, |
9 | DescriptorDatabase, | 7 | DescriptorDatabase, |
10 | function::{FnId, FnScopes}, | ||
11 | }, | ||
12 | }; | 8 | }; |
13 | 9 | ||
14 | /// Resolve `FnId` to the corresponding `SyntaxNode` | 10 | /// Resolve `FnId` to the corresponding `SyntaxNode` |
diff --git a/crates/ra_analysis/src/descriptors/function/mod.rs b/crates/ra_analysis/src/descriptors/function/mod.rs index ae40f3e8f..d5db28a64 100644 --- a/crates/ra_analysis/src/descriptors/function/mod.rs +++ b/crates/ra_analysis/src/descriptors/function/mod.rs | |||
@@ -1,20 +1,16 @@ | |||
1 | pub(super) mod imp; | 1 | pub(super) mod imp; |
2 | mod scope; | 2 | mod scope; |
3 | 3 | ||
4 | use std::cmp::{min, max}; | 4 | use std::cmp::{max, min}; |
5 | 5 | ||
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, | 7 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, |
8 | TextRange, TextUnit | 8 | TextRange, TextUnit, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{syntax_ptr::SyntaxPtr, FileId}; |
12 | FileId, | ||
13 | syntax_ptr::SyntaxPtr | ||
14 | }; | ||
15 | |||
16 | pub(crate) use self::scope::{FnScopes, resolve_local_name}; | ||
17 | 12 | ||
13 | pub(crate) use self::scope::{resolve_local_name, FnScopes}; | ||
18 | 14 | ||
19 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
20 | pub(crate) struct FnId(SyntaxPtr); | 16 | pub(crate) struct FnId(SyntaxPtr); |
@@ -26,14 +22,13 @@ impl FnId { | |||
26 | } | 22 | } |
27 | } | 23 | } |
28 | 24 | ||
29 | |||
30 | #[derive(Debug, Clone)] | 25 | #[derive(Debug, Clone)] |
31 | pub struct FnDescriptor { | 26 | pub struct FnDescriptor { |
32 | pub name: String, | 27 | pub name: String, |
33 | pub label: String, | 28 | pub label: String, |
34 | pub ret_type: Option<String>, | 29 | pub ret_type: Option<String>, |
35 | pub params: Vec<String>, | 30 | pub params: Vec<String>, |
36 | pub doc: Option<String> | 31 | pub doc: Option<String>, |
37 | } | 32 | } |
38 | 33 | ||
39 | impl FnDescriptor { | 34 | impl FnDescriptor { |
@@ -57,7 +52,9 @@ impl FnDescriptor { | |||
57 | }; | 52 | }; |
58 | 53 | ||
59 | if let Some((comment_range, docs)) = FnDescriptor::extract_doc_comments(node) { | 54 | if let Some((comment_range, docs)) = FnDescriptor::extract_doc_comments(node) { |
60 | let comment_range = comment_range.checked_sub(node.syntax().range().start()).unwrap(); | 55 | let comment_range = comment_range |
56 | .checked_sub(node.syntax().range().start()) | ||
57 | .unwrap(); | ||
61 | let start = comment_range.start().to_usize(); | 58 | let start = comment_range.start().to_usize(); |
62 | let end = comment_range.end().to_usize(); | 59 | let end = comment_range.end().to_usize(); |
63 | 60 | ||
@@ -94,7 +91,7 @@ impl FnDescriptor { | |||
94 | ret_type, | 91 | ret_type, |
95 | params, | 92 | params, |
96 | label: label.trim().to_owned(), | 93 | label: label.trim().to_owned(), |
97 | doc | 94 | doc, |
98 | }) | 95 | }) |
99 | } | 96 | } |
100 | 97 | ||
@@ -105,10 +102,13 @@ impl FnDescriptor { | |||
105 | 102 | ||
106 | let comment_text = node.doc_comment_text(); | 103 | let comment_text = node.doc_comment_text(); |
107 | 104 | ||
108 | let (begin, end) = node.doc_comments() | 105 | let (begin, end) = node |
106 | .doc_comments() | ||
109 | .map(|comment| comment.syntax().range()) | 107 | .map(|comment| comment.syntax().range()) |
110 | .map(|range| (range.start().to_usize(), range.end().to_usize())) | 108 | .map(|range| (range.start().to_usize(), range.end().to_usize())) |
111 | .fold((std::usize::MAX, std::usize::MIN), |acc, range| (min(acc.0, range.0), max(acc.1, range.1))); | 109 | .fold((std::usize::MAX, std::usize::MIN), |acc, range| { |
110 | (min(acc.0, range.0), max(acc.1, range.1)) | ||
111 | }); | ||
112 | 112 | ||
113 | let range = TextRange::from_to(TextUnit::from_usize(begin), TextUnit::from_usize(end)); | 113 | let range = TextRange::from_to(TextUnit::from_usize(begin), TextUnit::from_usize(end)); |
114 | 114 | ||
@@ -134,4 +134,3 @@ impl FnDescriptor { | |||
134 | res | 134 | res |
135 | } | 135 | } |
136 | } | 136 | } |
137 | |||
diff --git a/crates/ra_analysis/src/descriptors/function/scope.rs b/crates/ra_analysis/src/descriptors/function/scope.rs index d9929414c..62b46ffba 100644 --- a/crates/ra_analysis/src/descriptors/function/scope.rs +++ b/crates/ra_analysis/src/descriptors/function/scope.rs | |||
@@ -51,9 +51,7 @@ impl FnScopes { | |||
51 | &self.get(scope).entries | 51 | &self.get(scope).entries |
52 | } | 52 | } |
53 | pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { | 53 | pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { |
54 | generate(self.scope_for(node), move |&scope| { | 54 | generate(self.scope_for(node), move |&scope| self.get(scope).parent) |
55 | self.get(scope).parent | ||
56 | }) | ||
57 | } | 55 | } |
58 | fn root_scope(&mut self) -> ScopeId { | 56 | fn root_scope(&mut self) -> ScopeId { |
59 | let res = ScopeId(self.scopes.len() as u32); | 57 | let res = ScopeId(self.scopes.len() as u32); |
@@ -273,13 +271,12 @@ pub fn resolve_local_name<'a>( | |||
273 | 271 | ||
274 | #[cfg(test)] | 272 | #[cfg(test)] |
275 | mod tests { | 273 | mod tests { |
274 | use ra_editor::find_node_at_offset; | ||
276 | use ra_syntax::File; | 275 | use ra_syntax::File; |
277 | use test_utils::extract_offset; | 276 | use test_utils::extract_offset; |
278 | use ra_editor::{find_node_at_offset}; | ||
279 | 277 | ||
280 | use super::*; | 278 | use super::*; |
281 | 279 | ||
282 | |||
283 | fn do_check(code: &str, expected: &[&str]) { | 280 | fn do_check(code: &str, expected: &[&str]) { |
284 | let (off, code) = extract_offset(code); | 281 | let (off, code) = extract_offset(code); |
285 | let code = { | 282 | let code = { |