diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/macros.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 1 |
2 files changed, 3 insertions, 24 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index a8070637e..dd477e9f9 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs | |||
@@ -11,7 +11,7 @@ use std::sync::Arc; | |||
11 | 11 | ||
12 | use ra_syntax::{ | 12 | use ra_syntax::{ |
13 | TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreeArc, SyntaxNodePtr, | 13 | TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreeArc, SyntaxNodePtr, |
14 | ast::{self, NameOwner}, | 14 | ast, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use crate::{MacroCallId, PersistentHirDatabase}; | 17 | use crate::{MacroCallId, PersistentHirDatabase}; |
@@ -20,7 +20,6 @@ use crate::{MacroCallId, PersistentHirDatabase}; | |||
20 | #[derive(Debug, Clone, PartialEq, Eq)] | 20 | #[derive(Debug, Clone, PartialEq, Eq)] |
21 | pub enum MacroDef { | 21 | pub enum MacroDef { |
22 | Vec, | 22 | Vec, |
23 | QueryGroup, | ||
24 | } | 23 | } |
25 | 24 | ||
26 | impl MacroDef { | 25 | impl MacroDef { |
@@ -39,8 +38,6 @@ impl MacroDef { | |||
39 | let name_ref = path.segment()?.name_ref()?; | 38 | let name_ref = path.segment()?.name_ref()?; |
40 | if name_ref.text() == "vec" { | 39 | if name_ref.text() == "vec" { |
41 | MacroDef::Vec | 40 | MacroDef::Vec |
42 | } else if name_ref.text() == "query_group" { | ||
43 | MacroDef::QueryGroup | ||
44 | } else { | 41 | } else { |
45 | return None; | 42 | return None; |
46 | } | 43 | } |
@@ -56,7 +53,6 @@ impl MacroDef { | |||
56 | fn expand(self, input: MacroInput) -> Option<MacroExpansion> { | 53 | fn expand(self, input: MacroInput) -> Option<MacroExpansion> { |
57 | match self { | 54 | match self { |
58 | MacroDef::Vec => self.expand_vec(input), | 55 | MacroDef::Vec => self.expand_vec(input), |
59 | MacroDef::QueryGroup => self.expand_query_group(input), | ||
60 | } | 56 | } |
61 | } | 57 | } |
62 | fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { | 58 | fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { |
@@ -69,24 +65,6 @@ impl MacroDef { | |||
69 | let res = MacroExpansion { text, ranges_map, ptr }; | 65 | let res = MacroExpansion { text, ranges_map, ptr }; |
70 | Some(res) | 66 | Some(res) |
71 | } | 67 | } |
72 | fn expand_query_group(self, input: MacroInput) -> Option<MacroExpansion> { | ||
73 | let anchor = "trait "; | ||
74 | let pos = input.text.find(anchor)? + anchor.len(); | ||
75 | let trait_name = | ||
76 | input.text[pos..].chars().take_while(|c| c.is_alphabetic()).collect::<String>(); | ||
77 | if trait_name.is_empty() { | ||
78 | return None; | ||
79 | } | ||
80 | let src_range = TextRange::offset_len((pos as u32).into(), TextUnit::of_str(&trait_name)); | ||
81 | let text = format!(r"trait {} {{ }}", trait_name); | ||
82 | let file = SourceFile::parse(&text); | ||
83 | let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?; | ||
84 | let name = trait_def.name()?; | ||
85 | let ptr = SyntaxNodePtr::new(trait_def.syntax()); | ||
86 | let ranges_map = vec![(src_range, name.syntax().range())]; | ||
87 | let res = MacroExpansion { text, ranges_map, ptr }; | ||
88 | Some(res) | ||
89 | } | ||
90 | } | 68 | } |
91 | 69 | ||
92 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 70 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -109,7 +87,7 @@ pub struct MacroExpansion { | |||
109 | } | 87 | } |
110 | 88 | ||
111 | impl MacroExpansion { | 89 | impl MacroExpansion { |
112 | // FIXME: does not really make sense, macro expansion is not neccessary a | 90 | // FIXME: does not really make sense, macro expansion is not necessary a |
113 | // whole file. See `MacroExpansion::ptr` as well. | 91 | // whole file. See `MacroExpansion::ptr` as well. |
114 | pub(crate) fn file(&self) -> TreeArc<SourceFile> { | 92 | pub(crate) fn file(&self) -> TreeArc<SourceFile> { |
115 | SourceFile::parse(&self.text) | 93 | SourceFile::parse(&self.text) |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index f1a1f5b76..6dbe759d1 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -326,6 +326,7 @@ fn name_res_works_for_broken_modules() { | |||
326 | } | 326 | } |
327 | 327 | ||
328 | #[test] | 328 | #[test] |
329 | #[ignore] | ||
329 | fn item_map_contains_items_from_expansions() { | 330 | fn item_map_contains_items_from_expansions() { |
330 | let (item_map, module_id) = item_map( | 331 | let (item_map, module_id) = item_map( |
331 | " | 332 | " |