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 <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-02-01 07:54:32 +00:00
commit 21c5935931
5 changed files with 16 additions and 73 deletions

View File

@ -19,7 +19,6 @@
// Hard-coded defs for now :-(
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MacroDef {
CTry,
Vec,
QueryGroup,
}
@ -38,9 +37,7 @@ fn from_call(macro_call: &ast::MacroCall) -> Option<(MacroDef, MacroInput)> {
let def = {
let path = macro_call.path()?;
let name_ref = path.segment()?.name_ref()?;
if name_ref.text() == "ctry" {
MacroDef::CTry
} else if name_ref.text() == "vec" {
if name_ref.text() == "vec" {
MacroDef::Vec
} else if name_ref.text() == "query_group" {
MacroDef::QueryGroup
@ -60,35 +57,10 @@ fn from_call(macro_call: &ast::MacroCall) -> Option<(MacroDef, MacroInput)> {
fn expand(self, input: MacroInput) -> Option<MacroExpansion> {
match self {
MacroDef::CTry => self.expand_ctry(input),
MacroDef::Vec => self.expand_vec(input),
MacroDef::QueryGroup => self.expand_query_group(input),
}
}
fn expand_ctry(self, input: MacroInput) -> Option<MacroExpansion> {
let text = format!(
r"
fn dummy() {{
match {} {{
None => return Ok(None),
Some(it) => it,
}}
}}",
input.text
);
let file = SourceFile::parse(&text);
let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?;
let match_arg = match_expr.expr()?;
let ptr = SyntaxNodePtr::new(match_arg.syntax());
let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
let ranges_map = vec![(src_range, match_arg.syntax().range())];
let res = MacroExpansion {
text,
ranges_map,
ptr,
};
Some(res)
}
fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> {
let text = format!(r"fn dummy() {{ {}; }}", input.text);
let file = SourceFile::parse(&text);

View File

@ -47,11 +47,11 @@ fn extend_selection_inside_macros() {
let (analysis, frange) = single_file_with_range(
"
fn main() {
ctry!(foo(|x| <|>x<|>));
vec![foo(|x| <|>x<|>)];
}
",
);
let r = analysis.extend_selection(frange).unwrap();
assert_eq!(r, TextRange::from_to(51.into(), 56.into()));
assert_eq!(r, TextRange::from_to(50.into(), 55.into()));
}
}

View File

@ -1,8 +1,8 @@
---
created: "2019-01-22T14:45:01.017117100+00:00"
creator: insta@0.4.0
created: "2019-02-01T07:52:15.689836752+00:00"
creator: insta@0.5.3
expression: "&highlights"
source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs"
source: crates/ra_ide_api/src/syntax_highlighting.rs
---
[
HighlightedRange {

View File

@ -1,8 +1,8 @@
---
created: "2019-01-22T14:45:01.043047100+00:00"
creator: insta@0.4.0
created: "2019-02-01T07:46:59.130146403+00:00"
creator: insta@0.5.3
expression: "&highlights"
source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs"
source: crates/ra_ide_api/src/syntax_highlighting.rs
---
[
HighlightedRange {
@ -14,59 +14,31 @@ source: "crates\\ra_ide_api\\src\\syntax_highlighting.rs"
tag: "function"
},
HighlightedRange {
range: [41; 46),
range: [41; 45),
tag: "macro"
},
HighlightedRange {
range: [49; 52),
range: [48; 51),
tag: "keyword"
},
HighlightedRange {
range: [57; 59),
range: [56; 58),
tag: "literal"
},
HighlightedRange {
range: [82; 86),
tag: "macro"
},
HighlightedRange {
range: [89; 92),
range: [48; 51),
tag: "keyword"
},
HighlightedRange {
range: [97; 99),
tag: "literal"
},
HighlightedRange {
range: [49; 52),
tag: "keyword"
},
HighlightedRange {
range: [53; 54),
range: [52; 53),
tag: "function"
},
HighlightedRange {
range: [57; 59),
range: [56; 58),
tag: "literal"
},
HighlightedRange {
range: [61; 62),
tag: "text"
},
HighlightedRange {
range: [89; 92),
tag: "keyword"
},
HighlightedRange {
range: [93; 94),
tag: "function"
},
HighlightedRange {
range: [97; 99),
tag: "literal"
},
HighlightedRange {
range: [101; 102),
range: [60; 61),
tag: "text"
}
]

View File

@ -42,7 +42,6 @@ fn highlights_code_inside_macros() {
let (analysis, file_id) = single_file(
"
fn main() {
ctry!({ let x = 92; x});
vec![{ let x = 92; x}];
}
",