aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-22 14:56:59 +0000
committerLukas Wirth <[email protected]>2021-03-23 10:32:14 +0000
commit7c4eb66c1acf10216fa866e05d646bdaea229ded (patch)
tree89df7b614ec5f88d7a4e43313e84d62c12cbceee
parentbad4e48672f928644457cece3b7e21dd78ea1e9b (diff)
Merge hir::MacroDef::is_* into hir::MacroDef::kind
-rw-r--r--crates/hir/src/lib.rs31
-rw-r--r--crates/ide_completion/src/completions/attribute.rs3
-rw-r--r--crates/ide_db/src/search.rs2
3 files changed, 20 insertions, 16 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index ea0a60961..5da6a0340 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1117,6 +1117,14 @@ impl BuiltinType {
1117} 1117}
1118 1118
1119#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 1119#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1120pub enum MacroKind {
1121 Declarative,
1122 ProcMacro,
1123 Derive,
1124 BuiltIn,
1125}
1126
1127#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1120pub struct MacroDef { 1128pub struct MacroDef {
1121 pub(crate) id: MacroDefId, 1129 pub(crate) id: MacroDefId,
1122} 1130}
@@ -1140,20 +1148,15 @@ impl MacroDef {
1140 } 1148 }
1141 } 1149 }
1142 1150
1143 /// Indicate it is a proc-macro 1151 pub fn kind(&self) -> MacroKind {
1144 pub fn is_proc_macro(&self) -> bool { 1152 match self.id.kind {
1145 matches!(self.id.kind, MacroDefKind::ProcMacro(..)) 1153 MacroDefKind::Declarative(_) => MacroKind::Declarative,
1146 } 1154 MacroDefKind::BuiltIn(_, _) => MacroKind::BuiltIn,
1147 1155 MacroDefKind::BuiltInDerive(_, _) => MacroKind::Derive,
1148 /// Indicate it is a derive macro 1156 MacroDefKind::BuiltInEager(_, _) => MacroKind::BuiltIn,
1149 pub fn is_derive_macro(&self) -> bool { 1157 // FIXME might be a derive
1150 // FIXME: wrong for `ProcMacro` 1158 MacroDefKind::ProcMacro(_, _) => MacroKind::ProcMacro,
1151 matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..)) 1159 }
1152 }
1153
1154 /// Indicate it is a declarative macro
1155 pub fn is_declarative(&self) -> bool {
1156 matches!(self.id.kind, MacroDefKind::Declarative(..))
1157 } 1160 }
1158} 1161}
1159 1162
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs
index e846678b4..b1505c74b 100644
--- a/crates/ide_completion/src/completions/attribute.rs
+++ b/crates/ide_completion/src/completions/attribute.rs
@@ -246,7 +246,8 @@ fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> {
246 let mut result = FxHashSet::default(); 246 let mut result = FxHashSet::default();
247 ctx.scope.process_all_names(&mut |name, scope_def| { 247 ctx.scope.process_all_names(&mut |name, scope_def| {
248 if let hir::ScopeDef::MacroDef(mac) = scope_def { 248 if let hir::ScopeDef::MacroDef(mac) = scope_def {
249 if mac.is_derive_macro() { 249 // FIXME kind() doesn't check whether proc-macro is a derive
250 if mac.kind() == hir::MacroKind::Derive || mac.kind() == hir::MacroKind::ProcMacro {
250 result.insert(name.to_string()); 251 result.insert(name.to_string());
251 } 252 }
252 } 253 }
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 5fdcb13cf..ff958c757 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -257,7 +257,7 @@ impl Definition {
257 }; 257 };
258 258
259 if let Definition::Macro(macro_def) = self { 259 if let Definition::Macro(macro_def) = self {
260 if macro_def.is_declarative() { 260 if macro_def.kind() == hir::MacroKind::Declarative {
261 return if macro_def.attrs(db).by_key("macro_export").exists() { 261 return if macro_def.attrs(db).by_key("macro_export").exists() {
262 rev_dep_scope() 262 rev_dep_scope()
263 } else { 263 } else {