diff options
author | Aleksey Kladov <[email protected]> | 2020-02-27 10:37:21 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-27 10:37:21 +0000 |
commit | 819bbd08645a85cbf31025b31bd4daf69f821d20 (patch) | |
tree | 65d297cd72a90e310eab38146b0b76e66bd5d85f /crates | |
parent | 405e3d20a902cff0db74b9d69a812a201301cd2d (diff) |
Minor cleanup
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 5f11b091c..22d0ed3e6 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -46,32 +46,35 @@ fn is_control_keyword(kind: SyntaxKind) -> bool { | |||
46 | pub(crate) fn highlight( | 46 | pub(crate) fn highlight( |
47 | db: &RootDatabase, | 47 | db: &RootDatabase, |
48 | file_id: FileId, | 48 | file_id: FileId, |
49 | range: Option<TextRange>, | 49 | range_to_highlight: Option<TextRange>, |
50 | ) -> Vec<HighlightedRange> { | 50 | ) -> Vec<HighlightedRange> { |
51 | let _p = profile("highlight"); | 51 | let _p = profile("highlight"); |
52 | let sema = Semantics::new(db); | 52 | let sema = Semantics::new(db); |
53 | let root = sema.parse(file_id).syntax().clone(); | 53 | |
54 | // Determine the root based on the given range. | ||
55 | let (root, range_to_highlight) = { | ||
56 | let source_file = sema.parse(file_id); | ||
57 | match range_to_highlight { | ||
58 | Some(range) => { | ||
59 | let node = match source_file.syntax().covering_element(range) { | ||
60 | NodeOrToken::Node(it) => it, | ||
61 | NodeOrToken::Token(it) => it.parent(), | ||
62 | }; | ||
63 | (node, range) | ||
64 | } | ||
65 | None => (source_file.syntax().clone(), source_file.syntax().text_range()), | ||
66 | } | ||
67 | }; | ||
54 | 68 | ||
55 | let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); | 69 | let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default(); |
56 | let mut res = Vec::new(); | 70 | let mut res = Vec::new(); |
57 | 71 | ||
58 | let mut in_macro_call = None; | 72 | let mut in_macro_call = None; |
59 | 73 | ||
60 | // Determine the root based on the given range. | ||
61 | let (root, highlight_range) = if let Some(range) = range { | ||
62 | let root = match root.covering_element(range) { | ||
63 | NodeOrToken::Node(node) => node, | ||
64 | NodeOrToken::Token(token) => token.parent(), | ||
65 | }; | ||
66 | (root, range) | ||
67 | } else { | ||
68 | (root.clone(), root.text_range()) | ||
69 | }; | ||
70 | |||
71 | for event in root.preorder_with_tokens() { | 74 | for event in root.preorder_with_tokens() { |
72 | match event { | 75 | match event { |
73 | WalkEvent::Enter(node) => { | 76 | WalkEvent::Enter(node) => { |
74 | if node.text_range().intersection(&highlight_range).is_none() { | 77 | if node.text_range().intersection(&range_to_highlight).is_none() { |
75 | continue; | 78 | continue; |
76 | } | 79 | } |
77 | 80 | ||
@@ -115,7 +118,7 @@ pub(crate) fn highlight( | |||
115 | } | 118 | } |
116 | } | 119 | } |
117 | WalkEvent::Leave(node) => { | 120 | WalkEvent::Leave(node) => { |
118 | if node.text_range().intersection(&highlight_range).is_none() { | 121 | if node.text_range().intersection(&range_to_highlight).is_none() { |
119 | continue; | 122 | continue; |
120 | } | 123 | } |
121 | 124 | ||