aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/syntax_highlighting.rs')
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs36
1 files changed, 2 insertions, 34 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 345b6653d..fdd87bcff 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,4 +1,4 @@
1use ra_syntax::{ast, AstNode,}; 1use ra_syntax::AstNode;
2use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
3 3
4use crate::{ 4use crate::{
@@ -8,37 +8,5 @@ use crate::{
8 8
9pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 9pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
10 let source_file = db.parse(file_id); 10 let source_file = db.parse(file_id);
11 let mut res = ra_ide_api_light::highlight(source_file.syntax()); 11 ra_ide_api_light::highlight(source_file.syntax())
12 for macro_call in source_file.syntax().descendants().filter_map(ast::MacroCall::cast) {
13 if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) {
14 let mapped_ranges =
15 ra_ide_api_light::highlight(&exp.syntax()).into_iter().filter_map(|r| {
16 let mapped_range = exp.map_range_back(r.range)?;
17 let res = HighlightedRange { range: mapped_range + off, tag: r.tag };
18 Some(res)
19 });
20 res.extend(mapped_ranges);
21 }
22 }
23 res
24}
25
26#[cfg(test)]
27mod tests {
28 use crate::mock_analysis::single_file;
29
30 use insta::assert_debug_snapshot_matches;
31
32 #[test]
33 fn highlights_code_inside_macros() {
34 let (analysis, file_id) = single_file(
35 "
36 fn main() {
37 vec![{ let x = 92; x}];
38 }
39 ",
40 );
41 let highlights = analysis.highlight(file_id).unwrap();
42 assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
43 }
44} 12}