From 5bf3e949e8470a138a61c806769e1a329761cab6 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Thu, 23 May 2019 19:42:42 +0200 Subject: Semantic highlighting spike Very simple approach: For each identifier, set the hash of the range where it's defined as its 'id' and use it in the VSCode extension to generate unique colors. Thus, the generated colors are per-file. They are also quite fragile, and I'm not entirely sure why. Looks like we need to make sure the same ranges aren't overwritten by a later request? --- crates/ra_syntax/src/syntax_node.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 80054f529..89f92e0b7 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -523,6 +523,10 @@ impl<'a> SyntaxElement<'a> { } } + pub fn as_ast_node(&self) -> Option<&T> { + self.as_node().and_then(|x| ::cast(x)) + } + pub fn as_token(&self) -> Option> { match self { SyntaxElement::Node(_) => None, -- cgit v1.2.3