diff options
author | Aleksey Kladov <[email protected]> | 2019-07-12 17:41:13 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-12 17:41:13 +0100 |
commit | deab4caa7b1ba81c1b7e6561bc270bbde6467f13 (patch) | |
tree | af552549d828905294f4f3c109cdc339c12020ad /crates/ra_ide_api/src/syntax_highlighting.rs | |
parent | 2e466bb365813620de15afd5e04736a92fffdca9 (diff) |
make Parse fields private
this is in preparation for the new rowan API
Diffstat (limited to 'crates/ra_ide_api/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide_api/src/syntax_highlighting.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 7c4285b02..d70ceb7d1 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -32,7 +32,8 @@ fn is_control_keyword(kind: SyntaxKind) -> bool { | |||
32 | 32 | ||
33 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { | 33 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { |
34 | let _p = profile("highlight"); | 34 | let _p = profile("highlight"); |
35 | let source_file = db.parse(file_id).tree; | 35 | let parse = db.parse(file_id); |
36 | let root = parse.tree().syntax(); | ||
36 | 37 | ||
37 | fn calc_binding_hash(file_id: FileId, text: &SmolStr, shadow_count: u32) -> u64 { | 38 | fn calc_binding_hash(file_id: FileId, text: &SmolStr, shadow_count: u32) -> u64 { |
38 | fn hash<T: std::hash::Hash + std::fmt::Debug>(x: T) -> u64 { | 39 | fn hash<T: std::hash::Hash + std::fmt::Debug>(x: T) -> u64 { |
@@ -51,7 +52,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
51 | let mut bindings_shadow_count: FxHashMap<SmolStr, u32> = FxHashMap::default(); | 52 | let mut bindings_shadow_count: FxHashMap<SmolStr, u32> = FxHashMap::default(); |
52 | 53 | ||
53 | let mut res = Vec::new(); | 54 | let mut res = Vec::new(); |
54 | for node in source_file.syntax().descendants_with_tokens() { | 55 | for node in root.descendants_with_tokens() { |
55 | if highlighted.contains(&node) { | 56 | if highlighted.contains(&node) { |
56 | continue; | 57 | continue; |
57 | } | 58 | } |
@@ -89,11 +90,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
89 | Some(SelfType(_)) => "type", | 90 | Some(SelfType(_)) => "type", |
90 | Some(Pat(ptr)) => { | 91 | Some(Pat(ptr)) => { |
91 | binding_hash = Some({ | 92 | binding_hash = Some({ |
92 | let text = ptr | 93 | let text = |
93 | .syntax_node_ptr() | 94 | ptr.syntax_node_ptr().to_node(root).text().to_smol_string(); |
94 | .to_node(&source_file.syntax()) | ||
95 | .text() | ||
96 | .to_smol_string(); | ||
97 | let shadow_count = | 95 | let shadow_count = |
98 | bindings_shadow_count.entry(text.clone()).or_default(); | 96 | bindings_shadow_count.entry(text.clone()).or_default(); |
99 | calc_binding_hash(file_id, &text, *shadow_count) | 97 | calc_binding_hash(file_id, &text, *shadow_count) |
@@ -178,7 +176,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
178 | } | 176 | } |
179 | 177 | ||
180 | pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { | 178 | pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: bool) -> String { |
181 | let source_file = db.parse(file_id).tree; | 179 | let parse = db.parse(file_id); |
182 | 180 | ||
183 | fn rainbowify(seed: u64) -> String { | 181 | fn rainbowify(seed: u64) -> String { |
184 | use rand::prelude::*; | 182 | use rand::prelude::*; |
@@ -200,7 +198,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
200 | let mut buf = String::new(); | 198 | let mut buf = String::new(); |
201 | buf.push_str(&STYLE); | 199 | buf.push_str(&STYLE); |
202 | buf.push_str("<pre><code>"); | 200 | buf.push_str("<pre><code>"); |
203 | let tokens = source_file.syntax().descendants_with_tokens().filter_map(|it| it.as_token()); | 201 | let tokens = parse.tree().syntax().descendants_with_tokens().filter_map(|it| it.as_token()); |
204 | for token in tokens { | 202 | for token in tokens { |
205 | could_intersect.retain(|it| token.range().start() <= it.range.end()); | 203 | could_intersect.retain(|it| token.range().start() <= it.range.end()); |
206 | while let Some(r) = ranges.get(frontier) { | 204 | while let Some(r) = ranges.get(frontier) { |