From de85f1e94740d9a19066f7fda2e57d26973e472c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 1 Feb 2019 10:52:36 +0300 Subject: remove hard-coded support for ctry macro It was used mainly to prevent HirFileId infra from bitroting, but the `vec![]` macro can serve that just as well! --- crates/ra_hir/src/macros.rs | 30 +------------- crates/ra_ide_api/src/extend_selection.rs | 4 +- .../tests__highlight_query_group_macro.snap | 6 +-- .../tests__highlights_code_inside_macros.snap | 48 +++++----------------- crates/ra_ide_api/src/syntax_highlighting.rs | 1 - 5 files changed, 16 insertions(+), 73 deletions(-) (limited to 'crates') 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}; // Hard-coded defs for now :-( #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum MacroDef { - CTry, Vec, QueryGroup, } @@ -38,9 +37,7 @@ impl MacroDef { 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 @@ impl MacroDef { fn expand(self, input: MacroInput) -> Option { 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 { - 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 { let text = format!(r"fn dummy() {{ {}; }}", input.text); 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 { 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())); } } 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 @@ --- -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 { 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 @@ --- -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), - tag: "keyword" - }, - HighlightedRange { - range: [97; 99), - tag: "literal" - }, - HighlightedRange { - range: [49; 52), - tag: "keyword" - }, - HighlightedRange { - range: [53; 54), - tag: "function" - }, - HighlightedRange { - range: [57; 59), - tag: "literal" - }, - HighlightedRange { - range: [61; 62), - tag: "text" - }, - HighlightedRange { - range: [89; 92), + range: [48; 51), tag: "keyword" }, HighlightedRange { - range: [93; 94), + range: [52; 53), tag: "function" }, HighlightedRange { - range: [97; 99), + range: [56; 58), tag: "literal" }, HighlightedRange { - range: [101; 102), + range: [60; 61), tag: "text" } ] 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 { let (analysis, file_id) = single_file( " fn main() { - ctry!({ let x = 92; x}); vec![{ let x = 92; x}]; } ", -- cgit v1.2.3