mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
generalize highlighting to work with nodes
This commit is contained in:
parent
f1e8ebfbeb
commit
862c99d0d5
2 changed files with 5 additions and 5 deletions
|
@ -9,14 +9,14 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
|
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
|
||||||
let source_file = db.source_file(file_id);
|
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
|
for macro_call in source_file
|
||||||
.syntax()
|
.syntax()
|
||||||
.descendants()
|
.descendants()
|
||||||
.filter_map(ast::MacroCall::cast)
|
.filter_map(ast::MacroCall::cast)
|
||||||
{
|
{
|
||||||
if let Some(exp) = crate::macros::expand(db, file_id, macro_call) {
|
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()
|
.into_iter()
|
||||||
.filter_map(|r| {
|
.filter_map(|r| {
|
||||||
let mapped_range = exp.map_range_back(r.range)?;
|
let mapped_range = exp.map_range_back(r.range)?;
|
||||||
|
|
|
@ -79,11 +79,11 @@ pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUni
|
||||||
Some(matching_node.range().start())
|
Some(matching_node.range().start())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight(file: &SourceFileNode) -> Vec<HighlightedRange> {
|
pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> {
|
||||||
// Visited nodes to handle highlighting priorities
|
// Visited nodes to handle highlighting priorities
|
||||||
let mut highlighted = FxHashSet::default();
|
let mut highlighted = FxHashSet::default();
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for node in file.syntax().descendants() {
|
for node in root.descendants() {
|
||||||
if highlighted.contains(&node) {
|
if highlighted.contains(&node) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ fn main() {}
|
||||||
println!("Hello, {}!", 92);
|
println!("Hello, {}!", 92);
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
let hls = highlight(&file);
|
let hls = highlight(file.syntax());
|
||||||
assert_eq_dbg(
|
assert_eq_dbg(
|
||||||
r#"[HighlightedRange { range: [1; 11), tag: "comment" },
|
r#"[HighlightedRange { range: [1; 11), tag: "comment" },
|
||||||
HighlightedRange { range: [12; 14), tag: "keyword" },
|
HighlightedRange { range: [12; 14), tag: "keyword" },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue