diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-02 13:05:54 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-02 13:05:54 +0000 |
commit | afa972e78d2d81598c02b742ab84d70c88208300 (patch) | |
tree | 2ec32a586d0ee00e0d35a489efeaf31c91d14a15 /crates/ra_analysis/src/syntax_highlighting.rs | |
parent | e4ffd7b31780b1f2ac6dcb731566b583bf562647 (diff) | |
parent | 1076e82856f353763de8426d378fcd1e371cbed4 (diff) |
Merge #403
403: initial support for macros r=matklad a=matklad
I'll write a more comprehensive description when this is closer to being done. Basically this investigates one question: "how do we represent code which is a result of a macro call". This is an interesting question: currently everything is `FileId` based, but macro expansion does not have a file!
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_analysis/src/syntax_highlighting.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 7e9139a74..ccea4aee3 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs | |||
@@ -15,13 +15,13 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi | |||
15 | .descendants() | 15 | .descendants() |
16 | .filter_map(ast::MacroCall::cast) | 16 | .filter_map(ast::MacroCall::cast) |
17 | { | 17 | { |
18 | if let Some(exp) = crate::macros::expand(db, file_id, macro_call) { | 18 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { |
19 | let mapped_ranges = ra_editor::highlight(exp.source_file().syntax()) | 19 | let mapped_ranges = ra_editor::highlight(exp.syntax().borrowed()) |
20 | .into_iter() | 20 | .into_iter() |
21 | .filter_map(|r| { | 21 | .filter_map(|r| { |
22 | let mapped_range = exp.map_range_back(r.range)?; | 22 | let mapped_range = exp.map_range_back(r.range)?; |
23 | let res = HighlightedRange { | 23 | let res = HighlightedRange { |
24 | range: mapped_range, | 24 | range: mapped_range + off, |
25 | tag: r.tag, | 25 | tag: r.tag, |
26 | }; | 26 | }; |
27 | Some(res) | 27 | Some(res) |
@@ -44,7 +44,7 @@ mod tests { | |||
44 | fn main() { | 44 | fn main() { |
45 | ctry!({ let x = 92; x}); | 45 | ctry!({ let x = 92; x}); |
46 | } | 46 | } |
47 | ", | 47 | ", |
48 | ); | 48 | ); |
49 | let highlights = analysis.highlight(file_id).unwrap(); | 49 | let highlights = analysis.highlight(file_id).unwrap(); |
50 | assert_eq_dbg( | 50 | assert_eq_dbg( |
@@ -60,4 +60,26 @@ mod tests { | |||
60 | &highlights, | 60 | &highlights, |
61 | ) | 61 | ) |
62 | } | 62 | } |
63 | |||
64 | // FIXME: this test is not really necessary: artifact of the inital hacky | ||
65 | // macros implementation. | ||
66 | #[test] | ||
67 | fn highlight_query_group_macro() { | ||
68 | let (analysis, file_id) = single_file( | ||
69 | " | ||
70 | salsa::query_group! { | ||
71 | pub trait HirDatabase: SyntaxDatabase {} | ||
72 | } | ||
73 | ", | ||
74 | ); | ||
75 | let highlights = analysis.highlight(file_id).unwrap(); | ||
76 | assert_eq_dbg( | ||
77 | r#"[HighlightedRange { range: [20; 32), tag: "macro" }, | ||
78 | HighlightedRange { range: [13; 18), tag: "text" }, | ||
79 | HighlightedRange { range: [51; 54), tag: "keyword" }, | ||
80 | HighlightedRange { range: [55; 60), tag: "keyword" }, | ||
81 | HighlightedRange { range: [61; 72), tag: "function" }]"#, | ||
82 | &highlights, | ||
83 | ) | ||
84 | } | ||
63 | } | 85 | } |