aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-01 07:54:32 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-01 07:54:32 +0000
commit21c593593163c22b996f7c8bffe05b9708f5b2d0 (patch)
tree7346c0bed5398138702c83aafff7ee6752e821ab /crates
parent9d3f4624e1a83eb945f4df6427fc650356ea77fa (diff)
parentde85f1e94740d9a19066f7fda2e57d26973e472c (diff)
Merge #722
722: remove hard-coded support for ctry macro r=matklad a=matklad It was used mainly to prevent HirFileId infra from bitroting, but the `vec![]` macro can serve that just as well! Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/macros.rs30
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs4
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap6
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap48
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs1
5 files changed, 16 insertions, 73 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs
index 7ca34d434..cf7220875 100644
--- a/crates/ra_hir/src/macros.rs
+++ b/crates/ra_hir/src/macros.rs
@@ -19,7 +19,6 @@ use crate::{HirDatabase, MacroCallId};
19// Hard-coded defs for now :-( 19// Hard-coded defs for now :-(
20#[derive(Debug, Clone, PartialEq, Eq, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum MacroDef { 21pub enum MacroDef {
22 CTry,
23 Vec, 22 Vec,
24 QueryGroup, 23 QueryGroup,
25} 24}
@@ -38,9 +37,7 @@ impl MacroDef {
38 let def = { 37 let def = {
39 let path = macro_call.path()?; 38 let path = macro_call.path()?;
40 let name_ref = path.segment()?.name_ref()?; 39 let name_ref = path.segment()?.name_ref()?;
41 if name_ref.text() == "ctry" { 40 if name_ref.text() == "vec" {
42 MacroDef::CTry
43 } else if name_ref.text() == "vec" {
44 MacroDef::Vec 41 MacroDef::Vec
45 } else if name_ref.text() == "query_group" { 42 } else if name_ref.text() == "query_group" {
46 MacroDef::QueryGroup 43 MacroDef::QueryGroup
@@ -60,35 +57,10 @@ impl MacroDef {
60 57
61 fn expand(self, input: MacroInput) -> Option<MacroExpansion> { 58 fn expand(self, input: MacroInput) -> Option<MacroExpansion> {
62 match self { 59 match self {
63 MacroDef::CTry => self.expand_ctry(input),
64 MacroDef::Vec => self.expand_vec(input), 60 MacroDef::Vec => self.expand_vec(input),
65 MacroDef::QueryGroup => self.expand_query_group(input), 61 MacroDef::QueryGroup => self.expand_query_group(input),
66 } 62 }
67 } 63 }
68 fn expand_ctry(self, input: MacroInput) -> Option<MacroExpansion> {
69 let text = format!(
70 r"
71 fn dummy() {{
72 match {} {{
73 None => return Ok(None),
74 Some(it) => it,
75 }}
76 }}",
77 input.text
78 );
79 let file = SourceFile::parse(&text);
80 let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?;
81 let match_arg = match_expr.expr()?;
82 let ptr = SyntaxNodePtr::new(match_arg.syntax());
83 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
84 let ranges_map = vec![(src_range, match_arg.syntax().range())];
85 let res = MacroExpansion {
86 text,
87 ranges_map,
88 ptr,
89 };
90 Some(res)
91 }
92 fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { 64 fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> {
93 let text = format!(r"fn dummy() {{ {}; }}", input.text); 65 let text = format!(r"fn dummy() {{ {}; }}", input.text);
94 let file = SourceFile::parse(&text); 66 let file = SourceFile::parse(&text);
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index cd2ebe471..f61feaf1b 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -47,11 +47,11 @@ mod tests {
47 let (analysis, frange) = single_file_with_range( 47 let (analysis, frange) = single_file_with_range(
48 " 48 "
49 fn main() { 49 fn main() {
50 ctry!(foo(|x| <|>x<|>)); 50 vec![foo(|x| <|>x<|>)];
51 } 51 }
52 ", 52 ",
53 ); 53 );
54 let r = analysis.extend_selection(frange).unwrap(); 54 let r = analysis.extend_selection(frange).unwrap();
55 assert_eq!(r, TextRange::from_to(51.into(), 56.into())); 55 assert_eq!(r, TextRange::from_to(50.into(), 55.into()));
56 } 56 }
57} 57}
diff --git a/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
index 062add083..0b802ac3d 100644
--- a/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
+++ b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
@@ -1,8 +1,8 @@
1--- 1---
2created: "2019-01-22T14:45:01.017117100+00:00" 2created: "2019-02-01T07:52:15.689836752+00:00"
3creator: insta@0.4.0 3creator: insta@0.5.3
4expression: "&highlights" 4expression: "&highlights"
5source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs" 5source: crates/ra_ide_api/src/syntax_highlighting.rs
6--- 6---
7[ 7[
8 HighlightedRange { 8 HighlightedRange {
diff --git a/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap
index fd8265abb..ae8923e75 100644
--- a/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap
+++ b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap
@@ -1,8 +1,8 @@
1--- 1---
2created: "2019-01-22T14:45:01.043047100+00:00" 2created: "2019-02-01T07:46:59.130146403+00:00"
3creator: insta@0.4.0 3creator: insta@0.5.3
4expression: "&highlights" 4expression: "&highlights"
5source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs" 5source: crates/ra_ide_api/src/syntax_highlighting.rs
6--- 6---
7[ 7[
8 HighlightedRange { 8 HighlightedRange {
@@ -14,59 +14,31 @@ source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs"
14 tag: "function" 14 tag: "function"
15 }, 15 },
16 HighlightedRange { 16 HighlightedRange {
17 range: [41; 46), 17 range: [41; 45),
18 tag: "macro" 18 tag: "macro"
19 }, 19 },
20 HighlightedRange { 20 HighlightedRange {
21 range: [49; 52), 21 range: [48; 51),
22 tag: "keyword" 22 tag: "keyword"
23 }, 23 },
24 HighlightedRange { 24 HighlightedRange {
25 range: [57; 59), 25 range: [56; 58),
26 tag: "literal" 26 tag: "literal"
27 }, 27 },
28 HighlightedRange { 28 HighlightedRange {
29 range: [82; 86), 29 range: [48; 51),
30 tag: "macro"
31 },
32 HighlightedRange {
33 range: [89; 92),
34 tag: "keyword"
35 },
36 HighlightedRange {
37 range: [97; 99),
38 tag: "literal"
39 },
40 HighlightedRange {
41 range: [49; 52),
42 tag: "keyword"
43 },
44 HighlightedRange {
45 range: [53; 54),
46 tag: "function"
47 },
48 HighlightedRange {
49 range: [57; 59),
50 tag: "literal"
51 },
52 HighlightedRange {
53 range: [61; 62),
54 tag: "text"
55 },
56 HighlightedRange {
57 range: [89; 92),
58 tag: "keyword" 30 tag: "keyword"
59 }, 31 },
60 HighlightedRange { 32 HighlightedRange {
61 range: [93; 94), 33 range: [52; 53),
62 tag: "function" 34 tag: "function"
63 }, 35 },
64 HighlightedRange { 36 HighlightedRange {
65 range: [97; 99), 37 range: [56; 58),
66 tag: "literal" 38 tag: "literal"
67 }, 39 },
68 HighlightedRange { 40 HighlightedRange {
69 range: [101; 102), 41 range: [60; 61),
70 tag: "text" 42 tag: "text"
71 } 43 }
72] 44]
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 26bde495b..6c4391e1e 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -42,7 +42,6 @@ mod tests {
42 let (analysis, file_id) = single_file( 42 let (analysis, file_id) = single_file(
43 " 43 "
44 fn main() { 44 fn main() {
45 ctry!({ let x = 92; x});
46 vec![{ let x = 92; x}]; 45 vec![{ let x = 92; x}];
47 } 46 }
48 ", 47 ",