mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
allow expanding expressions
This commit is contained in:
parent
16c7405262
commit
caa8663c08
2 changed files with 8 additions and 7 deletions
|
@ -830,14 +830,11 @@ where
|
||||||
|
|
||||||
if let Some(def) = self.resolver.resolve_macro_call(path) {
|
if let Some(def) = self.resolver.resolve_macro_call(path) {
|
||||||
let call_id = MacroCallLoc { def, ast_id }.id(self.db);
|
let call_id = MacroCallLoc { def, ast_id }.id(self.db);
|
||||||
if let Some(tt) = self.db.macro_expand(call_id).ok() {
|
let file_id = call_id.as_file(MacroFileKind::Expr);
|
||||||
if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() {
|
if let Some(node) = self.db.parse_or_expand(file_id) {
|
||||||
|
if let Some(expr) = ast::Expr::cast(&*node) {
|
||||||
log::debug!("macro expansion {}", expr.syntax().debug_dump());
|
log::debug!("macro expansion {}", expr.syntax().debug_dump());
|
||||||
let old_file_id = std::mem::replace(
|
let old_file_id = std::mem::replace(&mut self.current_file_id, file_id);
|
||||||
&mut self.current_file_id,
|
|
||||||
//BUG
|
|
||||||
call_id.as_file(MacroFileKind::Items),
|
|
||||||
);
|
|
||||||
let id = self.collect_expr(&expr);
|
let id = self.collect_expr(&expr);
|
||||||
self.current_file_id = old_file_id;
|
self.current_file_id = old_file_id;
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -81,6 +81,9 @@ impl HirFileId {
|
||||||
MacroFileKind::Items => {
|
MacroFileKind::Items => {
|
||||||
Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned())
|
Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned())
|
||||||
}
|
}
|
||||||
|
MacroFileKind::Expr => {
|
||||||
|
mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +105,7 @@ struct MacroFile {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum MacroFileKind {
|
pub(crate) enum MacroFileKind {
|
||||||
Items,
|
Items,
|
||||||
|
Expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FileId> for HirFileId {
|
impl From<FileId> for HirFileId {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue