diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/fn_references.rs | 21 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 2 |
3 files changed, 26 insertions, 14 deletions
diff --git a/crates/ide/src/fn_references.rs b/crates/ide/src/fn_references.rs new file mode 100644 index 000000000..ca91b98cf --- /dev/null +++ b/crates/ide/src/fn_references.rs | |||
@@ -0,0 +1,21 @@ | |||
1 | use hir::Semantics; | ||
2 | use ide_db::RootDatabase; | ||
3 | use syntax::{ast, ast::NameOwner, AstNode, SyntaxNode}; | ||
4 | |||
5 | use crate::{runnables::has_test_related_attribute, FileId, FileRange}; | ||
6 | |||
7 | pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec<FileRange> { | ||
8 | let sema = Semantics::new(db); | ||
9 | let source_file = sema.parse(file_id); | ||
10 | source_file.syntax().descendants().filter_map(|it| method_range(it, file_id)).collect() | ||
11 | } | ||
12 | |||
13 | pub(crate) fn method_range(item: SyntaxNode, file_id: FileId) -> Option<FileRange> { | ||
14 | ast::Fn::cast(item).and_then(|fn_def|{ | ||
15 | if has_test_related_attribute(&fn_def) { | ||
16 | None | ||
17 | } else { | ||
18 | fn_def.name().map(|name| FileRange{ file_id, range: name.syntax().text_range() }) | ||
19 | } | ||
20 | }) | ||
21 | } | ||
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 286a6a110..31f2bcba3 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -38,6 +38,7 @@ mod join_lines; | |||
38 | mod matching_brace; | 38 | mod matching_brace; |
39 | mod parent_module; | 39 | mod parent_module; |
40 | mod references; | 40 | mod references; |
41 | mod fn_references; | ||
41 | mod runnables; | 42 | mod runnables; |
42 | mod status; | 43 | mod status; |
43 | mod syntax_highlighting; | 44 | mod syntax_highlighting; |
@@ -56,7 +57,7 @@ use ide_db::{ | |||
56 | symbol_index::{self, FileSymbol}, | 57 | symbol_index::{self, FileSymbol}, |
57 | LineIndexDatabase, | 58 | LineIndexDatabase, |
58 | }; | 59 | }; |
59 | use syntax::{SourceFile, SyntaxKind, TextRange, TextSize}; | 60 | use syntax::{SourceFile, TextRange, TextSize}; |
60 | 61 | ||
61 | use crate::display::ToNav; | 62 | use crate::display::ToNav; |
62 | 63 | ||
@@ -369,19 +370,9 @@ impl Analysis { | |||
369 | }) | 370 | }) |
370 | } | 371 | } |
371 | 372 | ||
372 | /// Finds all methods and free functions for the file. | 373 | /// Finds all methods and free functions for the file. Does not return tests! |
373 | pub fn find_all_methods(&self, file_id: FileId) -> Cancelable<Vec<FileRange>> { | 374 | pub fn find_all_methods(&self, file_id: FileId) -> Cancelable<Vec<FileRange>> { |
374 | let res = self | 375 | self.with_db(|db| fn_references::find_all_methods(db, file_id)) |
375 | .file_structure(file_id)? | ||
376 | .into_iter() | ||
377 | .filter(|it| match it.kind { | ||
378 | SyntaxKind::FN => true, | ||
379 | _ => false, | ||
380 | }) | ||
381 | .filter_map(|it| Some(FileRange { file_id, range: it.navigation_range })) | ||
382 | .collect(); | ||
383 | |||
384 | Ok(res) | ||
385 | } | 376 | } |
386 | 377 | ||
387 | /// Returns a short text describing element at position. | 378 | /// Returns a short text describing element at position. |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 989a63c09..cfeff40c1 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -203,7 +203,7 @@ impl TestAttr { | |||
203 | /// | 203 | /// |
204 | /// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, | 204 | /// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, |
205 | /// but it's better than not to have the runnables for the tests at all. | 205 | /// but it's better than not to have the runnables for the tests at all. |
206 | fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { | 206 | pub(crate) fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { |
207 | fn_def | 207 | fn_def |
208 | .attrs() | 208 | .attrs() |
209 | .filter_map(|attr| attr.path()) | 209 | .filter_map(|attr| attr.path()) |