mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Fix mod item in included file resolving incorrectly
This commit is contained in:
parent
d2a31acda1
commit
5edf7bddc6
6 changed files with 39 additions and 36 deletions
|
@ -136,7 +136,7 @@ pub enum MacroDefKind {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
struct EagerCallInfo {
|
||||
pub struct EagerCallInfo {
|
||||
/// The expanded argument of the eager macro.
|
||||
arg: Arc<tt::Subtree>,
|
||||
/// Call id of the eager macro's input file (this is the macro file for its fully expanded input).
|
||||
|
@ -176,6 +176,8 @@ pub trait HirFileIdExt {
|
|||
/// expansion originated from.
|
||||
fn original_file(self, db: &dyn db::ExpandDatabase) -> FileId;
|
||||
|
||||
fn original_file_respecting_includes(self, db: &dyn db::ExpandDatabase) -> FileId;
|
||||
|
||||
/// If this is a macro call, returns the syntax node of the call.
|
||||
fn call_node(self, db: &dyn db::ExpandDatabase) -> Option<InFile<SyntaxNode>>;
|
||||
|
||||
|
@ -215,6 +217,29 @@ impl HirFileIdExt for HirFileId {
|
|||
}
|
||||
}
|
||||
|
||||
fn original_file_respecting_includes(mut self, db: &dyn db::ExpandDatabase) -> FileId {
|
||||
loop {
|
||||
match self.repr() {
|
||||
base_db::span::HirFileIdRepr::FileId(id) => break id,
|
||||
base_db::span::HirFileIdRepr::MacroFile(file) => {
|
||||
let loc = db.lookup_intern_macro_call(file.macro_call_id);
|
||||
if loc.def.is_include() {
|
||||
if let Some(eager) = &loc.eager {
|
||||
if let Ok(it) = builtin_fn_macro::include_input_to_file_id(
|
||||
db,
|
||||
file.macro_call_id,
|
||||
&eager.arg,
|
||||
) {
|
||||
break it;
|
||||
}
|
||||
}
|
||||
}
|
||||
self = loc.kind.file_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn call_node(self, db: &dyn db::ExpandDatabase) -> Option<InFile<SyntaxNode>> {
|
||||
let macro_file = self.macro_file()?;
|
||||
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
|
||||
|
@ -473,7 +498,7 @@ impl MacroCallKind {
|
|||
}
|
||||
|
||||
/// Returns the file containing the macro invocation.
|
||||
fn file_id(&self) -> HirFileId {
|
||||
pub fn file_id(&self) -> HirFileId {
|
||||
match *self {
|
||||
MacroCallKind::FnLike { ast_id: InFile { file_id, .. }, .. }
|
||||
| MacroCallKind::Derive { ast_id: InFile { file_id, .. }, .. }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue