mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 10:58:02 +00:00
Merge pull request #20612 from Veykril/veykril/push-vzuykrsxvrts
Some checks are pending
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
fix: Fix expand macro recursively not working correctly for nested macro calls
This commit is contained in:
commit
57ad00b07f
1 changed files with 49 additions and 46 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use hir::db::ExpandDatabase;
|
use hir::db::ExpandDatabase;
|
||||||
use hir::{ExpandResult, InFile, InRealFile, Semantics};
|
use hir::{ExpandResult, InFile, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
FileId, RootDatabase, base_db::Crate, helpers::pick_best_token,
|
FileId, RootDatabase, base_db::Crate, helpers::pick_best_token,
|
||||||
syntax_helpers::prettify_macro_expansion,
|
syntax_helpers::prettify_macro_expansion,
|
||||||
|
|
@ -87,14 +87,15 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
||||||
return derive;
|
return derive;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut anc = sema
|
let syntax_token = sema.descend_into_macros_exact(tok);
|
||||||
.descend_token_into_include_expansion(InRealFile::new(file_id, tok))
|
'tokens: for syntax_token in syntax_token {
|
||||||
.value
|
let mut anc = syntax_token.parent_ancestors();
|
||||||
.parent_ancestors();
|
|
||||||
let mut span_map = SpanMap::empty();
|
let mut span_map = SpanMap::empty();
|
||||||
let mut error = String::new();
|
let mut error = String::new();
|
||||||
let (name, expanded, kind) = loop {
|
let (name, expanded, kind) = loop {
|
||||||
let node = anc.next()?;
|
let Some(node) = anc.next() else {
|
||||||
|
continue 'tokens;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(item) = ast::Item::cast(node.clone())
|
if let Some(item) = ast::Item::cast(node.clone())
|
||||||
&& let Some(def) = sema.resolve_attr_macro_call(&item)
|
&& let Some(def) = sema.resolve_attr_macro_call(&item)
|
||||||
|
|
@ -132,7 +133,9 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
||||||
if !error.is_empty() {
|
if !error.is_empty() {
|
||||||
expansion.insert_str(0, &format!("Expansion had errors:{error}\n\n"));
|
expansion.insert_str(0, &format!("Expansion had errors:{error}\n\n"));
|
||||||
}
|
}
|
||||||
Some(ExpandedMacro { name, expansion })
|
return Some(ExpandedMacro { name, expansion });
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_macro_recur(
|
fn expand_macro_recur(
|
||||||
|
|
@ -752,8 +755,8 @@ fn test() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
my_concat!
|
concat!
|
||||||
"<>hi""#]],
|
"<>""#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue