aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs3
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs11
-rw-r--r--crates/ra_hir_expand/src/ast_id_map.rs2
-rw-r--r--crates/ra_syntax/src/ast/generated.rs10
-rw-r--r--crates/ra_syntax/src/ast/traits.rs31
6 files changed, 20 insertions, 41 deletions
diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs
index a63ef48b1..d86d804b2 100644
--- a/crates/ra_assists/src/handlers/add_explicit_type.rs
+++ b/crates/ra_assists/src/handlers/add_explicit_type.rs
@@ -130,8 +130,8 @@ mod tests {
130 fn add_explicit_type_works_for_macro_call() { 130 fn add_explicit_type_works_for_macro_call() {
131 check_assist( 131 check_assist(
132 add_explicit_type, 132 add_explicit_type,
133 "macro_rules! v { () => {0u64} } fn f() { let a<|> = v!(); }", 133 r"macro_rules! v { () => {0u64} } fn f() { let a<|> = v!(); }",
134 "macro_rules! v { () => {0u64} } fn f() { let a<|>: u64 = v!(); }", 134 r"macro_rules! v { () => {0u64} } fn f() { let a<|>: u64 = v!(); }",
135 ); 135 );
136 } 136 }
137 137
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 3cf0c66ea..e8443dde8 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -563,7 +563,8 @@ impl ExprCollector<'_> {
563 ast::ModuleItem::ImplDef(_) 563 ast::ModuleItem::ImplDef(_)
564 | ast::ModuleItem::UseItem(_) 564 | ast::ModuleItem::UseItem(_)
565 | ast::ModuleItem::ExternCrateItem(_) 565 | ast::ModuleItem::ExternCrateItem(_)
566 | ast::ModuleItem::Module(_) => continue, 566 | ast::ModuleItem::Module(_)
567 | ast::ModuleItem::MacroCall(_) => continue,
567 }; 568 };
568 self.body.item_scope.define_def(def); 569 self.body.item_scope.define_def(def);
569 if let Some(name) = name { 570 if let Some(name) = name {
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 1631e87b8..8f190e7f9 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -209,11 +209,8 @@ impl RawItemsCollector {
209 current_module: Option<Idx<ModuleData>>, 209 current_module: Option<Idx<ModuleData>>,
210 body: impl ast::ModuleItemOwner, 210 body: impl ast::ModuleItemOwner,
211 ) { 211 ) {
212 for item_or_macro in body.items_with_macros() { 212 for item in body.items() {
213 match item_or_macro { 213 self.add_item(current_module, item)
214 ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m),
215 ast::ItemOrMacro::Item(item) => self.add_item(current_module, item),
216 }
217 } 214 }
218 } 215 }
219 216
@@ -265,6 +262,10 @@ impl RawItemsCollector {
265 ast::ModuleItem::StaticDef(it) => { 262 ast::ModuleItem::StaticDef(it) => {
266 (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name()) 263 (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name())
267 } 264 }
265 ast::ModuleItem::MacroCall(it) => {
266 self.add_macro(current_module, it);
267 return;
268 }
268 }; 269 };
269 if let Some(name) = name { 270 if let Some(name) = name {
270 let name = name.as_name(); 271 let name = name.as_name();
diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs
index a6644d55f..5643ecdce 100644
--- a/crates/ra_hir_expand/src/ast_id_map.rs
+++ b/crates/ra_hir_expand/src/ast_id_map.rs
@@ -68,8 +68,6 @@ impl AstIdMap {
68 bfs(node, |it| { 68 bfs(node, |it| {
69 if let Some(module_item) = ast::ModuleItem::cast(it.clone()) { 69 if let Some(module_item) = ast::ModuleItem::cast(it.clone()) {
70 res.alloc(module_item.syntax()); 70 res.alloc(module_item.syntax());
71 } else if let Some(macro_call) = ast::MacroCall::cast(it) {
72 res.alloc(macro_call.syntax());
73 } 71 }
74 }); 72 });
75 res 73 res
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 002f453cd..7204ca5b1 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -4135,6 +4135,7 @@ pub enum ModuleItem {
4135 ConstDef(ConstDef), 4135 ConstDef(ConstDef),
4136 StaticDef(StaticDef), 4136 StaticDef(StaticDef),
4137 Module(Module), 4137 Module(Module),
4138 MacroCall(MacroCall),
4138} 4139}
4139impl From<StructDef> for ModuleItem { 4140impl From<StructDef> for ModuleItem {
4140 fn from(node: StructDef) -> ModuleItem { 4141 fn from(node: StructDef) -> ModuleItem {
@@ -4196,6 +4197,11 @@ impl From<Module> for ModuleItem {
4196 ModuleItem::Module(node) 4197 ModuleItem::Module(node)
4197 } 4198 }
4198} 4199}
4200impl From<MacroCall> for ModuleItem {
4201 fn from(node: MacroCall) -> ModuleItem {
4202 ModuleItem::MacroCall(node)
4203 }
4204}
4199impl std::fmt::Display for ModuleItem { 4205impl std::fmt::Display for ModuleItem {
4200 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 4206 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4201 std::fmt::Display::fmt(self.syntax(), f) 4207 std::fmt::Display::fmt(self.syntax(), f)
@@ -4205,7 +4211,7 @@ impl AstNode for ModuleItem {
4205 fn can_cast(kind: SyntaxKind) -> bool { 4211 fn can_cast(kind: SyntaxKind) -> bool {
4206 match kind { 4212 match kind {
4207 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF 4213 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
4208 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, 4214 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL => true,
4209 _ => false, 4215 _ => false,
4210 } 4216 }
4211 } 4217 }
@@ -4223,6 +4229,7 @@ impl AstNode for ModuleItem {
4223 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), 4229 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
4224 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), 4230 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
4225 MODULE => ModuleItem::Module(Module { syntax }), 4231 MODULE => ModuleItem::Module(Module { syntax }),
4232 MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
4226 _ => return None, 4233 _ => return None,
4227 }; 4234 };
4228 Some(res) 4235 Some(res)
@@ -4241,6 +4248,7 @@ impl AstNode for ModuleItem {
4241 ModuleItem::ConstDef(it) => &it.syntax, 4248 ModuleItem::ConstDef(it) => &it.syntax,
4242 ModuleItem::StaticDef(it) => &it.syntax, 4249 ModuleItem::StaticDef(it) => &it.syntax,
4243 ModuleItem::Module(it) => &it.syntax, 4250 ModuleItem::Module(it) => &it.syntax,
4251 ModuleItem::MacroCall(it) => &it.syntax,
4244 } 4252 }
4245 } 4253 }
4246} 4254}
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index f8cf1e3eb..576378306 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -6,8 +6,7 @@ use itertools::Itertools;
6 6
7use crate::{ 7use crate::{
8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, 8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken},
9 match_ast, 9 syntax_node::SyntaxElementChildren,
10 syntax_node::{SyntaxElementChildren, SyntaxNodeChildren},
11}; 10};
12 11
13pub trait TypeAscriptionOwner: AstNode { 12pub trait TypeAscriptionOwner: AstNode {
@@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode {
46 } 45 }
47} 46}
48 47
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum ItemOrMacro {
51 Item(ast::ModuleItem),
52 Macro(ast::MacroCall),
53}
54
55pub trait ModuleItemOwner: AstNode { 48pub trait ModuleItemOwner: AstNode {
56 fn items(&self) -> AstChildren<ast::ModuleItem> { 49 fn items(&self) -> AstChildren<ast::ModuleItem> {
57 children(self) 50 children(self)
58 } 51 }
59 fn items_with_macros(&self) -> ItemOrMacroIter {
60 ItemOrMacroIter(self.syntax().children())
61 }
62}
63
64#[derive(Debug)]
65pub struct ItemOrMacroIter(SyntaxNodeChildren);
66
67impl Iterator for ItemOrMacroIter {
68 type Item = ItemOrMacro;
69 fn next(&mut self) -> Option<ItemOrMacro> {
70 loop {
71 let n = self.0.next()?;
72 match_ast! {
73 match n {
74 ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) },
75 ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) },
76 _ => {},
77 }
78 }
79 }
80 }
81} 52}
82 53
83pub trait TypeParamsOwner: AstNode { 54pub trait TypeParamsOwner: AstNode {