aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/macros.rs26
-rw-r--r--crates/ra_hir/src/nameres/tests.rs1
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap28
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs15
-rw-r--r--crates/ra_ide_api/tests/test/main.rs1
5 files changed, 4 insertions, 67 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)
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index f1a1f5b76..6dbe759d1 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -326,6 +326,7 @@ fn name_res_works_for_broken_modules() {
326} 326}
327 327
328#[test] 328#[test]
329#[ignore]
329fn item_map_contains_items_from_expansions() { 330fn item_map_contains_items_from_expansions() {
330 let (item_map, module_id) = item_map( 331 let (item_map, module_id) = item_map(
331 " 332 "
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
deleted file mode 100644
index 0b802ac3d..000000000
--- a/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
+++ /dev/null
@@ -1,28 +0,0 @@
1---
2created: "2019-02-01T07:52:15.689836752+00:00"
3creator: [email protected]
4expression: "&highlights"
5source: crates/ra_ide_api/src/syntax_highlighting.rs
6---
7[
8 HighlightedRange {
9 range: [20; 32),
10 tag: "macro"
11 },
12 HighlightedRange {
13 range: [13; 18),
14 tag: "text"
15 },
16 HighlightedRange {
17 range: [51; 54),
18 tag: "keyword"
19 },
20 HighlightedRange {
21 range: [55; 60),
22 tag: "keyword"
23 },
24 HighlightedRange {
25 range: [61; 72),
26 tag: "function"
27 }
28]
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index a435fe56e..345b6653d 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -41,19 +41,4 @@ mod tests {
41 let highlights = analysis.highlight(file_id).unwrap(); 41 let highlights = analysis.highlight(file_id).unwrap();
42 assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights); 42 assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
43 } 43 }
44
45 // FIXME: this test is not really necessary: artifact of the inital hacky
46 // macros implementation.
47 #[test]
48 fn highlight_query_group_macro() {
49 let (analysis, file_id) = single_file(
50 "
51 salsa::query_group! {
52 pub trait HirDatabase: SyntaxDatabase {}
53 }
54 ",
55 );
56 let highlights = analysis.highlight(file_id).unwrap();
57 assert_debug_snapshot_matches!("highlight_query_group_macro", &highlights);
58 }
59} 44}
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs
index c2cb38f7e..7d1695cfd 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -91,6 +91,7 @@ fn test_find_all_refs_for_fn_param() {
91} 91}
92 92
93#[test] 93#[test]
94#[ignore]
94fn world_symbols_include_stuff_from_macros() { 95fn world_symbols_include_stuff_from_macros() {
95 let (analysis, _) = single_file( 96 let (analysis, _) = single_file(
96 " 97 "