mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Support cross-crate marks
This commit is contained in:
parent
437329d3f5
commit
19115e9fab
7 changed files with 37 additions and 4 deletions
|
@ -21,6 +21,7 @@ ra_syntax = { path = "../ra_syntax" }
|
|||
ra_text_edit = { path = "../ra_text_edit" }
|
||||
ra_db = { path = "../ra_db" }
|
||||
ra_prof = { path = "../ra_prof" }
|
||||
test_utils = { path = "../test_utils" }
|
||||
|
||||
# ra_ide should depend only on the top-level `hir` package. if you need
|
||||
# something from some `hir_xxx` subpackage, reexport the API via `hir`.
|
||||
|
|
|
@ -14,6 +14,7 @@ use ra_syntax::{
|
|||
ast::{self, AstNode, VisibilityOwner},
|
||||
match_ast,
|
||||
};
|
||||
use test_utils::tested_by;
|
||||
|
||||
use crate::RootDatabase;
|
||||
|
||||
|
@ -217,18 +218,22 @@ pub fn classify_name_ref(
|
|||
let parent = name_ref.syntax().parent()?;
|
||||
|
||||
if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
|
||||
tested_by!(goto_def_for_methods; force);
|
||||
if let Some(func) = sema.resolve_method_call(&method_call) {
|
||||
return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
|
||||
tested_by!(goto_def_for_fields; force);
|
||||
if let Some(field) = sema.resolve_field(&field_expr) {
|
||||
return Some(NameRefClass::Definition(Definition::StructField(field)));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
|
||||
tested_by!(goto_def_for_record_fields; force);
|
||||
tested_by!(goto_def_for_field_init_shorthand; force);
|
||||
if let Some((field, local)) = sema.resolve_record_field(&record_field) {
|
||||
let field = Definition::StructField(field);
|
||||
let res = match local {
|
||||
|
@ -240,6 +245,7 @@ pub fn classify_name_ref(
|
|||
}
|
||||
|
||||
if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
|
||||
tested_by!(goto_def_for_macros; force);
|
||||
if let Some(macro_def) = sema.resolve_macro_call(¯o_call) {
|
||||
return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
|
||||
|
||||
pub mod marks;
|
||||
pub mod line_index;
|
||||
pub mod line_index_utils;
|
||||
pub mod feature_flags;
|
||||
|
|
9
crates/ra_ide_db/src/marks.rs
Normal file
9
crates/ra_ide_db/src/marks.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
//! See test_utils/src/marks.rs
|
||||
|
||||
test_utils::marks![
|
||||
goto_def_for_macros
|
||||
goto_def_for_methods
|
||||
goto_def_for_fields
|
||||
goto_def_for_record_fields
|
||||
goto_def_for_field_init_shorthand
|
||||
];
|
Loading…
Add table
Add a link
Reference in a new issue