From 862c99d0d5ef7c791a9319fa76c436762d88460c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 31 Dec 2018 19:06:00 +0300 Subject: generalize highlighting to work with nodes --- crates/ra_analysis/src/syntax_highlighting.rs | 4 ++-- crates/ra_editor/src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 38219da71..7e9139a74 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs @@ -9,14 +9,14 @@ use crate::{ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable> { let source_file = db.source_file(file_id); - let mut res = ra_editor::highlight(&source_file); + let mut res = ra_editor::highlight(source_file.syntax()); for macro_call in source_file .syntax() .descendants() .filter_map(ast::MacroCall::cast) { if let Some(exp) = crate::macros::expand(db, file_id, macro_call) { - let mapped_ranges = ra_editor::highlight(exp.source_file()) + let mapped_ranges = ra_editor::highlight(exp.source_file().syntax()) .into_iter() .filter_map(|r| { let mapped_range = exp.map_range_back(r.range)?; diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index a65637d52..a293fec34 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs @@ -79,11 +79,11 @@ pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option Vec { +pub fn highlight(root: SyntaxNodeRef) -> Vec { // Visited nodes to handle highlighting priorities let mut highlighted = FxHashSet::default(); let mut res = Vec::new(); - for node in file.syntax().descendants() { + for node in root.descendants() { if highlighted.contains(&node) { continue; } @@ -178,7 +178,7 @@ fn main() {} println!("Hello, {}!", 92); "#, ); - let hls = highlight(&file); + let hls = highlight(file.syntax()); assert_eq_dbg( r#"[HighlightedRange { range: [1; 11), tag: "comment" }, HighlightedRange { range: [12; 14), tag: "keyword" }, -- cgit v1.2.3