diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/syntax_highlighting.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/macros.rs | 18 |
2 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index ccea4aee3..35e153ca0 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs | |||
@@ -43,6 +43,7 @@ mod tests { | |||
43 | " | 43 | " |
44 | fn main() { | 44 | fn main() { |
45 | ctry!({ let x = 92; x}); | 45 | ctry!({ let x = 92; x}); |
46 | vec![{ let x = 92; x}]; | ||
46 | } | 47 | } |
47 | ", | 48 | ", |
48 | ); | 49 | ); |
@@ -53,10 +54,17 @@ mod tests { | |||
53 | HighlightedRange { range: [41; 46), tag: "macro" }, | 54 | HighlightedRange { range: [41; 46), tag: "macro" }, |
54 | HighlightedRange { range: [49; 52), tag: "keyword" }, | 55 | HighlightedRange { range: [49; 52), tag: "keyword" }, |
55 | HighlightedRange { range: [57; 59), tag: "literal" }, | 56 | HighlightedRange { range: [57; 59), tag: "literal" }, |
57 | HighlightedRange { range: [82; 86), tag: "macro" }, | ||
58 | HighlightedRange { range: [89; 92), tag: "keyword" }, | ||
59 | HighlightedRange { range: [97; 99), tag: "literal" }, | ||
56 | HighlightedRange { range: [49; 52), tag: "keyword" }, | 60 | HighlightedRange { range: [49; 52), tag: "keyword" }, |
57 | HighlightedRange { range: [53; 54), tag: "function" }, | 61 | HighlightedRange { range: [53; 54), tag: "function" }, |
58 | HighlightedRange { range: [57; 59), tag: "literal" }, | 62 | HighlightedRange { range: [57; 59), tag: "literal" }, |
59 | HighlightedRange { range: [61; 62), tag: "text" }]"#, | 63 | HighlightedRange { range: [61; 62), tag: "text" }, |
64 | HighlightedRange { range: [89; 92), tag: "keyword" }, | ||
65 | HighlightedRange { range: [93; 94), tag: "function" }, | ||
66 | HighlightedRange { range: [97; 99), tag: "literal" }, | ||
67 | HighlightedRange { range: [101; 102), tag: "text" }]"#, | ||
60 | &highlights, | 68 | &highlights, |
61 | ) | 69 | ) |
62 | } | 70 | } |
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index b7b75e702..1b378c977 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs | |||
@@ -21,6 +21,7 @@ use crate::{HirDatabase, MacroCallId}; | |||
21 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 21 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
22 | pub enum MacroDef { | 22 | pub enum MacroDef { |
23 | CTry, | 23 | CTry, |
24 | Vec, | ||
24 | QueryGroup, | 25 | QueryGroup, |
25 | } | 26 | } |
26 | 27 | ||
@@ -40,6 +41,8 @@ impl MacroDef { | |||
40 | let name_ref = path.segment()?.name_ref()?; | 41 | let name_ref = path.segment()?.name_ref()?; |
41 | if name_ref.text() == "ctry" { | 42 | if name_ref.text() == "ctry" { |
42 | MacroDef::CTry | 43 | MacroDef::CTry |
44 | } else if name_ref.text() == "vec" { | ||
45 | MacroDef::Vec | ||
43 | } else if name_ref.text() == "query_group" { | 46 | } else if name_ref.text() == "query_group" { |
44 | MacroDef::QueryGroup | 47 | MacroDef::QueryGroup |
45 | } else { | 48 | } else { |
@@ -59,6 +62,7 @@ impl MacroDef { | |||
59 | fn expand(self, input: MacroInput) -> Option<MacroExpansion> { | 62 | fn expand(self, input: MacroInput) -> Option<MacroExpansion> { |
60 | match self { | 63 | match self { |
61 | MacroDef::CTry => self.expand_ctry(input), | 64 | MacroDef::CTry => self.expand_ctry(input), |
65 | MacroDef::Vec => self.expand_vec(input), | ||
62 | MacroDef::QueryGroup => self.expand_query_group(input), | 66 | MacroDef::QueryGroup => self.expand_query_group(input), |
63 | } | 67 | } |
64 | } | 68 | } |
@@ -86,6 +90,20 @@ impl MacroDef { | |||
86 | }; | 90 | }; |
87 | Some(res) | 91 | Some(res) |
88 | } | 92 | } |
93 | fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { | ||
94 | let text = format!(r"fn dummy() {{ {}; }}", input.text); | ||
95 | let file = SourceFileNode::parse(&text); | ||
96 | let array_expr = file.syntax().descendants().find_map(ast::ArrayExpr::cast)?; | ||
97 | let ptr = LocalSyntaxPtr::new(array_expr.syntax()); | ||
98 | let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text)); | ||
99 | let ranges_map = vec![(src_range, array_expr.syntax().range())]; | ||
100 | let res = MacroExpansion { | ||
101 | text, | ||
102 | ranges_map, | ||
103 | ptr, | ||
104 | }; | ||
105 | Some(res) | ||
106 | } | ||
89 | fn expand_query_group(self, input: MacroInput) -> Option<MacroExpansion> { | 107 | fn expand_query_group(self, input: MacroInput) -> Option<MacroExpansion> { |
90 | let anchor = "trait "; | 108 | let anchor = "trait "; |
91 | let pos = input.text.find(anchor)? + anchor.len(); | 109 | let pos = input.text.find(anchor)? + anchor.len(); |