diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index b4dcdba39..8e714a999 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -45,7 +45,7 @@ pub(crate) fn highlight( | |||
45 | file_id: FileId, | 45 | file_id: FileId, |
46 | range_to_highlight: Option<TextRange>, | 46 | range_to_highlight: Option<TextRange>, |
47 | syntactic_name_ref_highlighting: bool, | 47 | syntactic_name_ref_highlighting: bool, |
48 | default_tag: Option<HighlightTag>, | 48 | should_highlight_punctuation: bool, |
49 | ) -> Vec<HighlightedRange> { | 49 | ) -> Vec<HighlightedRange> { |
50 | let _p = profile("highlight"); | 50 | let _p = profile("highlight"); |
51 | let sema = Semantics::new(db); | 51 | let sema = Semantics::new(db); |
@@ -108,7 +108,7 @@ pub(crate) fn highlight( | |||
108 | &mut bindings_shadow_count, | 108 | &mut bindings_shadow_count, |
109 | syntactic_name_ref_highlighting, | 109 | syntactic_name_ref_highlighting, |
110 | name.syntax().clone().into(), | 110 | name.syntax().clone().into(), |
111 | default_tag, | 111 | should_highlight_punctuation, |
112 | ) { | 112 | ) { |
113 | stack.add(HighlightedRange { | 113 | stack.add(HighlightedRange { |
114 | range: name.syntax().text_range(), | 114 | range: name.syntax().text_range(), |
@@ -208,7 +208,7 @@ pub(crate) fn highlight( | |||
208 | &mut bindings_shadow_count, | 208 | &mut bindings_shadow_count, |
209 | syntactic_name_ref_highlighting, | 209 | syntactic_name_ref_highlighting, |
210 | element_to_highlight.clone(), | 210 | element_to_highlight.clone(), |
211 | default_tag, | 211 | true, |
212 | ) { | 212 | ) { |
213 | stack.add(HighlightedRange { range, highlight, binding_hash }); | 213 | stack.add(HighlightedRange { range, highlight, binding_hash }); |
214 | if let Some(string) = | 214 | if let Some(string) = |
@@ -331,12 +331,12 @@ impl HighlightedRangeStack { | |||
331 | /// can only modify the last range currently on the stack. | 331 | /// can only modify the last range currently on the stack. |
332 | /// Can be used to do injections that span multiple ranges, like the | 332 | /// Can be used to do injections that span multiple ranges, like the |
333 | /// doctest injection below. | 333 | /// doctest injection below. |
334 | /// If `delete` is set to true, the parent range is deleted instead of | 334 | /// If `inject` is set to true, the parent range is deleted instead of |
335 | /// intersected. | 335 | /// intersected. |
336 | /// | 336 | /// |
337 | /// Note that `pop` can be simulated by `pop_and_inject(false)` but the | 337 | /// Note that `pop` can be simulated by `pop_and_inject(false)` but the |
338 | /// latter is computationally more expensive. | 338 | /// latter is computationally more expensive. |
339 | fn pop_and_inject(&mut self, delete: bool) { | 339 | fn pop_and_inject(&mut self, inject: bool) { |
340 | let mut children = self.stack.pop().unwrap(); | 340 | let mut children = self.stack.pop().unwrap(); |
341 | let prev = self.stack.last_mut().unwrap(); | 341 | let prev = self.stack.last_mut().unwrap(); |
342 | children.sort_by_key(|range| range.range.start()); | 342 | children.sort_by_key(|range| range.range.start()); |
@@ -347,14 +347,14 @@ impl HighlightedRangeStack { | |||
347 | prev.iter().position(|parent| parent.range.contains_range(child.range)) | 347 | prev.iter().position(|parent| parent.range.contains_range(child.range)) |
348 | { | 348 | { |
349 | let cloned = Self::intersect(&mut prev[idx], &child); | 349 | let cloned = Self::intersect(&mut prev[idx], &child); |
350 | let insert_idx = if delete || prev[idx].range.is_empty() { | 350 | let insert_idx = if inject || prev[idx].range.is_empty() { |
351 | prev.remove(idx); | 351 | prev.remove(idx); |
352 | idx | 352 | idx |
353 | } else { | 353 | } else { |
354 | idx + 1 | 354 | idx + 1 |
355 | }; | 355 | }; |
356 | prev.insert(insert_idx, child); | 356 | prev.insert(insert_idx, child); |
357 | if !delete && !cloned.range.is_empty() { | 357 | if !inject && !cloned.range.is_empty() { |
358 | prev.insert(insert_idx + 1, cloned); | 358 | prev.insert(insert_idx + 1, cloned); |
359 | } | 359 | } |
360 | } else if let Some(_idx) = | 360 | } else if let Some(_idx) = |
@@ -433,14 +433,14 @@ fn highlight_element( | |||
433 | bindings_shadow_count: &mut FxHashMap<Name, u32>, | 433 | bindings_shadow_count: &mut FxHashMap<Name, u32>, |
434 | syntactic_name_ref_highlighting: bool, | 434 | syntactic_name_ref_highlighting: bool, |
435 | element: SyntaxElement, | 435 | element: SyntaxElement, |
436 | default_tag: Option<HighlightTag>, | 436 | should_highlight_punctuation: bool, |
437 | ) -> Option<(Highlight, Option<u64>)> { | 437 | ) -> Option<(Highlight, Option<u64>)> { |
438 | let db = sema.db; | 438 | let db = sema.db; |
439 | let mut binding_hash = None; | 439 | let mut binding_hash = None; |
440 | let highlight: Highlight = match element.kind() { | 440 | let highlight: Highlight = match element.kind() { |
441 | FN_DEF => { | 441 | FN_DEF => { |
442 | bindings_shadow_count.clear(); | 442 | bindings_shadow_count.clear(); |
443 | default_tag?.into() | 443 | return None; |
444 | } | 444 | } |
445 | 445 | ||
446 | // Highlight definitions depending on the "type" of the definition. | 446 | // Highlight definitions depending on the "type" of the definition. |
@@ -518,10 +518,10 @@ fn highlight_element( | |||
518 | 518 | ||
519 | let expr = prefix_expr.expr()?; | 519 | let expr = prefix_expr.expr()?; |
520 | let ty = sema.type_of_expr(&expr)?; | 520 | let ty = sema.type_of_expr(&expr)?; |
521 | let mut h = HighlightTag::Operator.into(); | ||
521 | if !ty.is_raw_ptr() { | 522 | if !ty.is_raw_ptr() { |
522 | default_tag?.into() | 523 | h |
523 | } else { | 524 | } else { |
524 | let mut h = Highlight::new(HighlightTag::Operator); | ||
525 | h |= HighlightModifier::Unsafe; | 525 | h |= HighlightModifier::Unsafe; |
526 | h | 526 | h |
527 | } | 527 | } |
@@ -550,7 +550,8 @@ fn highlight_element( | |||
550 | } | 550 | } |
551 | } | 551 | } |
552 | 552 | ||
553 | _ => default_tag?.into(), | 553 | p if should_highlight_punctuation && p.is_punct() => HighlightTag::Punctuation.into(), |
554 | _ => return None, | ||
554 | }; | 555 | }; |
555 | 556 | ||
556 | return Some((highlight, binding_hash)); | 557 | return Some((highlight, binding_hash)); |