in highlight/src/lib.rs [946:989]
fn enter_node(&mut self) {
let node = self.cursor.node();
let props = self.cursor.node_properties();
let node_text = if props.local_definition || props.local_reference {
node.utf8_text(self.cursor.source()).ok()
} else {
None
};
// If this node represents a local definition, then record its highlighting class
// and store the highlighting class in the current local scope.
if props.local_definition {
if let (Some(text), Some(inner_scope), Some(highlight)) =
(node_text, self.scope_stack.last_mut(), props.highlight)
{
self.local_highlight = props.highlight;
if let Err(i) = inner_scope.local_defs.binary_search_by_key(&text, |e| e.0) {
inner_scope.local_defs.insert(i, (text, highlight));
}
}
}
// If this node represents a local reference, then look it up in the current scope
// stack. If a local definition is found, record its highlighting class.
else if props.local_reference {
if let Some(text) = node_text {
for scope in self.scope_stack.iter().rev() {
if let Ok(i) = scope.local_defs.binary_search_by_key(&text, |e| e.0) {
self.local_highlight = Some(scope.local_defs[i].1);
break;
}
if !scope.inherits {
break;
}
}
}
}
// If this node represents a new local scope, then push it onto the scope stack.
if let Some(inherits) = props.local_scope {
self.scope_stack.push(Scope {
inherits,
local_defs: Vec::new(),
});
}
}