aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorvsrs <[email protected]>2020-09-02 15:27:57 +0100
committervsrs <[email protected]>2020-09-29 13:29:20 +0100
commit1895716c885eba9aae710f80f4c29eb2b424c6f0 (patch)
treef18ed9c1032465e8c715a5fdc66c7373b94bd1fb /crates
parent06fbd6905014b90aa2efc1f67b92f31845011d76 (diff)
Do not show references CodeLens for tests.
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/fn_references.rs21
-rw-r--r--crates/ide/src/lib.rs17
-rw-r--r--crates/ide/src/runnables.rs2
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 @@
1use hir::Semantics;
2use ide_db::RootDatabase;
3use syntax::{ast, ast::NameOwner, AstNode, SyntaxNode};
4
5use crate::{runnables::has_test_related_attribute, FileId, FileRange};
6
7pub(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
13pub(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;
38mod matching_brace; 38mod matching_brace;
39mod parent_module; 39mod parent_module;
40mod references; 40mod references;
41mod fn_references;
41mod runnables; 42mod runnables;
42mod status; 43mod status;
43mod syntax_highlighting; 44mod 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};
59use syntax::{SourceFile, SyntaxKind, TextRange, TextSize}; 60use syntax::{SourceFile, TextRange, TextSize};
60 61
61use crate::display::ToNav; 62use 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.
206fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { 206pub(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())