aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/macros.rs')
-rw-r--r--crates/ra_hir/src/macros.rs26
1 files changed, 2 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
12use ra_syntax::{ 12use 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
17use crate::{MacroCallId, PersistentHirDatabase}; 17use crate::{MacroCallId, PersistentHirDatabase};
@@ -20,7 +20,6 @@ use crate::{MacroCallId, PersistentHirDatabase};
20#[derive(Debug, Clone, PartialEq, Eq)] 20#[derive(Debug, Clone, PartialEq, Eq)]
21pub enum MacroDef { 21pub enum MacroDef {
22 Vec, 22 Vec,
23 QueryGroup,
24} 23}
25 24
26impl MacroDef { 25impl 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
111impl MacroExpansion { 89impl 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)