aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting/injection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting/injection.rs')
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 929a5cc5c..181c21256 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -7,7 +7,10 @@ use hir::Semantics;
7use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; 7use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use stdx::SepBy; 8use stdx::SepBy;
9 9
10use crate::{call_info::ActiveParameter, Analysis, HighlightTag, HighlightedRange, RootDatabase}; 10use crate::{
11 call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag,
12 HighlightedRange, RootDatabase,
13};
11 14
12use super::HighlightedRangeStack; 15use super::HighlightedRangeStack;
13 16
@@ -118,7 +121,7 @@ pub(super) fn extract_doc_comments(
118 range.start(), 121 range.start(),
119 range.start() + TextSize::try_from(pos).unwrap(), 122 range.start() + TextSize::try_from(pos).unwrap(),
120 ), 123 ),
121 highlight: HighlightTag::Comment.into(), 124 highlight: HighlightTag::Comment | HighlightModifier::Documentation,
122 binding_hash: None, 125 binding_hash: None,
123 }); 126 });
124 line_start += range.len() - TextSize::try_from(pos).unwrap(); 127 line_start += range.len() - TextSize::try_from(pos).unwrap();
@@ -152,18 +155,24 @@ pub(super) fn highlight_doc_comment(
152 let mut start_offset = None; 155 let mut start_offset = None;
153 let mut end_offset = None; 156 let mut end_offset = None;
154 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;
155 if line_start <= &h.range.start() { 162 if line_start <= &h.range.start() {
156 start_offset.get_or_insert(orig_line_start - line_start); 163 start_offset.get_or_insert(offset);
157 break; 164 break;
158 } else { 165 } else {
159 end_offset.get_or_insert(orig_line_start - line_start); 166 end_offset.get_or_insert(offset);
160 } 167 }
161 } 168 }
162 if let Some(start_offset) = start_offset { 169 if let Some(start_offset) = start_offset {
163 h.range = TextRange::new( 170 h.range = TextRange::new(
164 h.range.start() + start_offset, 171 start_offset,
165 h.range.end() + end_offset.unwrap_or(start_offset), 172 h.range.end() + end_offset.unwrap_or(start_offset) - h.range.start(),
166 ); 173 );
174
175 h.highlight |= HighlightModifier::Injected;
167 stack.add(h); 176 stack.add(h);
168 } 177 }
169 } 178 }
@@ -173,6 +182,7 @@ pub(super) fn highlight_doc_comment(
173 for comment in new_comments { 182 for comment in new_comments {
174 stack.add(comment); 183 stack.add(comment);
175 } 184 }
176 stack.pop_and_inject(false); 185 stack.pop_and_inject(None);
177 stack.pop_and_inject(true); 186 stack
187 .pop_and_inject(Some(Highlight::from(HighlightTag::Generic) | HighlightModifier::Injected));
178} 188}