Skip to content

Commit caa8663

Browse files
committed
allow expanding expressions
1 parent 16c7405 commit caa8663

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

crates/ra_hir/src/expr.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,11 @@ where
830830

831831
if let Some(def) = self.resolver.resolve_macro_call(path) {
832832
let call_id = MacroCallLoc { def, ast_id }.id(self.db);
833-
if let Some(tt) = self.db.macro_expand(call_id).ok() {
834-
if let Some(expr) = mbe::token_tree_to_expr(&tt).ok() {
833+
let file_id = call_id.as_file(MacroFileKind::Expr);
834+
if let Some(node) = self.db.parse_or_expand(file_id) {
835+
if let Some(expr) = ast::Expr::cast(&*node) {
835836
log::debug!("macro expansion {}", expr.syntax().debug_dump());
836-
let old_file_id = std::mem::replace(
837-
&mut self.current_file_id,
838-
//BUG
839-
call_id.as_file(MacroFileKind::Items),
840-
);
837+
let old_file_id = std::mem::replace(&mut self.current_file_id, file_id);
841838
let id = self.collect_expr(&expr);
842839
self.current_file_id = old_file_id;
843840
return id;

crates/ra_hir/src/ids.rs

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ impl HirFileId {
8181
MacroFileKind::Items => {
8282
Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned())
8383
}
84+
MacroFileKind::Expr => {
85+
mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned())
86+
}
8487
}
8588
}
8689
}
@@ -102,6 +105,7 @@ struct MacroFile {
102105
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
103106
pub(crate) enum MacroFileKind {
104107
Items,
108+
Expr,
105109
}
106110

107111
impl From<FileId> for HirFileId {

0 commit comments

Comments
 (0)