diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting/injection.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/injection.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index a6941234e..13dde1dc4 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs | |||
@@ -7,7 +7,7 @@ use ide_db::call_info::ActiveParameter; | |||
7 | use itertools::Itertools; | 7 | use itertools::Itertools; |
8 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 8 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
9 | 9 | ||
10 | use crate::{Analysis, HighlightedRange, HlMod, HlTag, RootDatabase}; | 10 | use crate::{Analysis, HlMod, HlRange, HlTag, RootDatabase}; |
11 | 11 | ||
12 | use super::{highlights::Highlights, injector::Injector}; | 12 | use super::{highlights::Highlights, injector::Injector}; |
13 | 13 | ||
@@ -26,11 +26,7 @@ pub(super) fn highlight_injection( | |||
26 | let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone()); | 26 | let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone()); |
27 | 27 | ||
28 | if let Some(range) = literal.open_quote_text_range() { | 28 | if let Some(range) = literal.open_quote_text_range() { |
29 | acc.add(HighlightedRange { | 29 | acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) |
30 | range, | ||
31 | highlight: HlTag::StringLiteral.into(), | ||
32 | binding_hash: None, | ||
33 | }) | ||
34 | } | 30 | } |
35 | 31 | ||
36 | for mut h in analysis.highlight(tmp_file_id).unwrap() { | 32 | for mut h in analysis.highlight(tmp_file_id).unwrap() { |
@@ -42,11 +38,7 @@ pub(super) fn highlight_injection( | |||
42 | } | 38 | } |
43 | 39 | ||
44 | if let Some(range) = literal.close_quote_text_range() { | 40 | if let Some(range) = literal.close_quote_text_range() { |
45 | acc.add(HighlightedRange { | 41 | acc.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) |
46 | range, | ||
47 | highlight: HlTag::StringLiteral.into(), | ||
48 | binding_hash: None, | ||
49 | }) | ||
50 | } | 42 | } |
51 | 43 | ||
52 | Some(()) | 44 | Some(()) |
@@ -116,7 +108,7 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[ | |||
116 | /// Lastly, a vector of new comment highlight ranges (spanning only the | 108 | /// Lastly, a vector of new comment highlight ranges (spanning only the |
117 | /// comment prefix) is returned which is used in the syntax highlighting | 109 | /// comment prefix) is returned which is used in the syntax highlighting |
118 | /// injection to replace the previous (line-spanning) comment ranges. | 110 | /// injection to replace the previous (line-spanning) comment ranges. |
119 | pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HighlightedRange>, Injector)> { | 111 | pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HlRange>, Injector)> { |
120 | let mut inj = Injector::default(); | 112 | let mut inj = Injector::default(); |
121 | // wrap the doctest into function body to get correct syntax highlighting | 113 | // wrap the doctest into function body to get correct syntax highlighting |
122 | let prefix = "fn doctest() {\n"; | 114 | let prefix = "fn doctest() {\n"; |
@@ -166,7 +158,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted | |||
166 | pos | 158 | pos |
167 | }; | 159 | }; |
168 | 160 | ||
169 | new_comments.push(HighlightedRange { | 161 | new_comments.push(HlRange { |
170 | range: TextRange::new( | 162 | range: TextRange::new( |
171 | range.start(), | 163 | range.start(), |
172 | range.start() + TextSize::try_from(pos).unwrap(), | 164 | range.start() + TextSize::try_from(pos).unwrap(), |
@@ -196,7 +188,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted | |||
196 | 188 | ||
197 | /// Injection of syntax highlighting of doctests. | 189 | /// Injection of syntax highlighting of doctests. |
198 | pub(super) fn highlight_doc_comment( | 190 | pub(super) fn highlight_doc_comment( |
199 | new_comments: Vec<HighlightedRange>, | 191 | new_comments: Vec<HlRange>, |
200 | inj: Injector, | 192 | inj: Injector, |
201 | stack: &mut Highlights, | 193 | stack: &mut Highlights, |
202 | ) { | 194 | ) { |
@@ -207,7 +199,7 @@ pub(super) fn highlight_doc_comment( | |||
207 | 199 | ||
208 | for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { | 200 | for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { |
209 | for r in inj.map_range_up(h.range) { | 201 | for r in inj.map_range_up(h.range) { |
210 | stack.add(HighlightedRange { | 202 | stack.add(HlRange { |
211 | range: r, | 203 | range: r, |
212 | highlight: h.highlight | HlMod::Injected, | 204 | highlight: h.highlight | HlMod::Injected, |
213 | binding_hash: h.binding_hash, | 205 | binding_hash: h.binding_hash, |