Do not show references CodeLens for tests.
This commit is contained in:
parent
06fbd69050
commit
1895716c88
3 changed files with 26 additions and 14 deletions
21
crates/ide/src/fn_references.rs
Normal file
21
crates/ide/src/fn_references.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use hir::Semantics;
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{ast, ast::NameOwner, AstNode, SyntaxNode};
|
||||
|
||||
use crate::{runnables::has_test_related_attribute, FileId, FileRange};
|
||||
|
||||
pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec<FileRange> {
|
||||
let sema = Semantics::new(db);
|
||||
let source_file = sema.parse(file_id);
|
||||
source_file.syntax().descendants().filter_map(|it| method_range(it, file_id)).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn method_range(item: SyntaxNode, file_id: FileId) -> Option<FileRange> {
|
||||
ast::Fn::cast(item).and_then(|fn_def|{
|
||||
if has_test_related_attribute(&fn_def) {
|
||||
None
|
||||
} else {
|
||||
fn_def.name().map(|name| FileRange{ file_id, range: name.syntax().text_range() })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ mod join_lines;
|
|||
mod matching_brace;
|
||||
mod parent_module;
|
||||
mod references;
|
||||
mod fn_references;
|
||||
mod runnables;
|
||||
mod status;
|
||||
mod syntax_highlighting;
|
||||
|
|
@ -56,7 +57,7 @@ use ide_db::{
|
|||
symbol_index::{self, FileSymbol},
|
||||
LineIndexDatabase,
|
||||
};
|
||||
use syntax::{SourceFile, SyntaxKind, TextRange, TextSize};
|
||||
use syntax::{SourceFile, TextRange, TextSize};
|
||||
|
||||
use crate::display::ToNav;
|
||||
|
||||
|
|
@ -369,19 +370,9 @@ impl Analysis {
|
|||
})
|
||||
}
|
||||
|
||||
/// Finds all methods and free functions for the file.
|
||||
/// Finds all methods and free functions for the file. Does not return tests!
|
||||
pub fn find_all_methods(&self, file_id: FileId) -> Cancelable<Vec<FileRange>> {
|
||||
let res = self
|
||||
.file_structure(file_id)?
|
||||
.into_iter()
|
||||
.filter(|it| match it.kind {
|
||||
SyntaxKind::FN => true,
|
||||
_ => false,
|
||||
})
|
||||
.filter_map(|it| Some(FileRange { file_id, range: it.navigation_range }))
|
||||
.collect();
|
||||
|
||||
Ok(res)
|
||||
self.with_db(|db| fn_references::find_all_methods(db, file_id))
|
||||
}
|
||||
|
||||
/// Returns a short text describing element at position.
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ impl TestAttr {
|
|||
///
|
||||
/// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test,
|
||||
/// but it's better than not to have the runnables for the tests at all.
|
||||
fn has_test_related_attribute(fn_def: &ast::Fn) -> bool {
|
||||
pub(crate) fn has_test_related_attribute(fn_def: &ast::Fn) -> bool {
|
||||
fn_def
|
||||
.attrs()
|
||||
.filter_map(|attr| attr.path())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue