diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/injection.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/injection.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs index 415f24a6d..181c21256 100644 --- a/crates/ra_ide/src/syntax_highlighting/injection.rs +++ b/crates/ra_ide/src/syntax_highlighting/injection.rs | |||
@@ -8,8 +8,8 @@ use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; | |||
8 | use stdx::SepBy; | 8 | use stdx::SepBy; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange, | 11 | call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag, |
12 | RootDatabase, | 12 | HighlightedRange, RootDatabase, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | use super::HighlightedRangeStack; | 15 | use super::HighlightedRangeStack; |
@@ -155,19 +155,24 @@ pub(super) fn highlight_doc_comment( | |||
155 | let mut start_offset = None; | 155 | let mut start_offset = None; |
156 | let mut end_offset = None; | 156 | let mut end_offset = None; |
157 | for (line_start, orig_line_start) in range_mapping.range(..h.range.end()).rev() { | 157 | for (line_start, orig_line_start) in range_mapping.range(..h.range.end()).rev() { |
158 | // It's possible for orig_line_start - line_start to be negative. Add h.range.start() | ||
159 | // here and remove it from the end range after the loop below so that the values are | ||
160 | // always non-negative. | ||
161 | let offset = h.range.start() + orig_line_start - line_start; | ||
158 | if line_start <= &h.range.start() { | 162 | if line_start <= &h.range.start() { |
159 | start_offset.get_or_insert(orig_line_start - line_start); | 163 | start_offset.get_or_insert(offset); |
160 | break; | 164 | break; |
161 | } else { | 165 | } else { |
162 | end_offset.get_or_insert(orig_line_start - line_start); | 166 | end_offset.get_or_insert(offset); |
163 | } | 167 | } |
164 | } | 168 | } |
165 | if let Some(start_offset) = start_offset { | 169 | if let Some(start_offset) = start_offset { |
166 | h.range = TextRange::new( | 170 | h.range = TextRange::new( |
167 | h.range.start() + start_offset, | 171 | start_offset, |
168 | h.range.end() + end_offset.unwrap_or(start_offset), | 172 | h.range.end() + end_offset.unwrap_or(start_offset) - h.range.start(), |
169 | ); | 173 | ); |
170 | 174 | ||
175 | h.highlight |= HighlightModifier::Injected; | ||
171 | stack.add(h); | 176 | stack.add(h); |
172 | } | 177 | } |
173 | } | 178 | } |
@@ -177,6 +182,7 @@ pub(super) fn highlight_doc_comment( | |||
177 | for comment in new_comments { | 182 | for comment in new_comments { |
178 | stack.add(comment); | 183 | stack.add(comment); |
179 | } | 184 | } |
180 | stack.pop_and_inject(false); | 185 | stack.pop_and_inject(None); |
181 | stack.pop_and_inject(true); | 186 | stack |
187 | .pop_and_inject(Some(Highlight::from(HighlightTag::Generic) | HighlightModifier::Injected)); | ||
182 | } | 188 | } |