aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/lib.rs4
-rw-r--r--crates/ra_ide/src/prime_caches.rs2
-rw-r--r--crates/ra_ide/src/snapshots/highlight_doctest.html44
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs18
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs6
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs3
-rw-r--r--crates/rust-analyzer/src/semantic_tokens.rs1
-rw-r--r--crates/rust-analyzer/src/to_proto.rs1
9 files changed, 47 insertions, 34 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index ecac5134e..22203b4a3 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -443,13 +443,13 @@ impl Analysis {
443 443
444 /// Computes syntax highlighting for the given file 444 /// Computes syntax highlighting for the given file
445 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 445 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
446 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false)) 446 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false, None))
447 } 447 }
448 448
449 /// Computes syntax highlighting for the given file range. 449 /// Computes syntax highlighting for the given file range.
450 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> { 450 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> {
451 self.with_db(|db| { 451 self.with_db(|db| {
452 syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false) 452 syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false, None)
453 }) 453 })
454 } 454 }
455 455
diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs
index c5ab5a1d8..dbed8a506 100644
--- a/crates/ra_ide/src/prime_caches.rs
+++ b/crates/ra_ide/src/prime_caches.rs
@@ -7,6 +7,6 @@ use crate::{FileId, RootDatabase};
7 7
8pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) { 8pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) {
9 for file in files { 9 for file in files {
10 let _ = crate::syntax_highlighting::highlight(db, file, None, false); 10 let _ = crate::syntax_highlighting::highlight(db, file, None, false, None);
11 } 11 }
12} 12}
diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html
index ac546806e..6b3932aff 100644
--- a/crates/ra_ide/src/snapshots/highlight_doctest.html
+++ b/crates/ra_ide/src/snapshots/highlight_doctest.html
@@ -47,9 +47,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
47 <span class="comment documentation">/// # Examples</span> 47 <span class="comment documentation">/// # Examples</span>
48 <span class="comment documentation">///</span> 48 <span class="comment documentation">///</span>
49 <span class="comment documentation">/// ```</span> 49 <span class="comment documentation">/// ```</span>
50 <span class="comment documentation">/// #</span> <span class="attribute">#![</span><span class="function attribute">allow</span><span class="attribute">(unused_mut)]</span> 50 <span class="comment documentation">/// #</span> <span class="operator injected">#</span><span class="operator injected">!</span><span class="operator injected">[</span><span class="operator injected">allow</span><span class="operator injected">(</span><span class="operator injected">unused_mut</span><span class="operator injected">)</span><span class="operator injected">]</span><span class="operator injected">
51 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">foo</span>: <span class="struct">Foo</span> = <span class="struct">Foo</span>::<span class="function">new</span>(); 51</span> <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="operator injected"> </span><span class="keyword injected">mut</span><span class="operator injected"> </span><span class="operator injected">foo</span><span class="operator injected">:</span><span class="operator injected"> </span><span class="operator injected">Foo</span><span class="operator injected"> </span><span class="operator injected">=</span><span class="operator injected"> </span><span class="operator injected">Foo</span><span class="operator injected">::</span><span class="operator injected">new</span><span class="operator injected">(</span><span class="operator injected">)</span><span class="operator injected">;</span><span class="operator injected">
52 <span class="comment documentation">/// ```</span> 52</span><span class="operator injected"> </span> <span class="comment documentation">/// ```</span>
53 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration">new</span>() -&gt; <span class="struct">Foo</span> { 53 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration">new</span>() -&gt; <span class="struct">Foo</span> {
54 <span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> } 54 <span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> }
55 } 55 }
@@ -59,27 +59,27 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
59 <span class="comment documentation">/// # Examples</span> 59 <span class="comment documentation">/// # Examples</span>
60 <span class="comment documentation">///</span> 60 <span class="comment documentation">///</span>
61 <span class="comment documentation">/// ```</span> 61 <span class="comment documentation">/// ```</span>
62 <span class="comment documentation">/// </span><span class="keyword">use</span> <span class="module">x</span>::<span class="module">y</span>; 62 <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="operator injected"> </span><span class="operator injected">x</span><span class="operator injected">::</span><span class="operator injected">y</span><span class="operator injected">;</span><span class="operator injected">
63 <span class="comment documentation">///</span> 63 </span><span class="comment documentation">///</span><span class="operator injected">
64 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">foo</span> = <span class="struct">Foo</span>::<span class="function">new</span>(); 64</span> <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="operator injected"> </span><span class="operator injected">foo</span><span class="operator injected"> </span><span class="operator injected">=</span><span class="operator injected"> </span><span class="operator injected">Foo</span><span class="operator injected">::</span><span class="operator injected">new</span><span class="operator injected">(</span><span class="operator injected">)</span><span class="operator injected">;</span><span class="operator injected">
65 <span class="comment documentation">///</span> 65 </span><span class="comment documentation">///</span><span class="operator injected">
66 <span class="comment documentation">/// </span><span class="comment">// calls bar on foo</span> 66</span> <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span><span class="operator injected">
67 <span class="comment documentation">/// </span><span class="macro">assert!</span>(foo.bar()); 67</span> <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="operator injected">(</span><span class="operator injected">foo</span><span class="operator injected">.</span><span class="operator injected">bar</span><span class="operator injected">(</span><span class="operator injected">)</span><span class="operator injected">)</span><span class="operator injected">;</span><span class="operator injected">
68 <span class="comment documentation">///</span> 68 </span><span class="comment documentation">///</span><span class="operator injected">
69 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">bar</span> = <span class="variable">foo</span>.<span class="field">bar</span> || <span class="struct">Foo</span>::<span class="constant">bar</span>; 69</span> <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="operator injected"> </span><span class="operator injected">bar</span><span class="operator injected"> </span><span class="operator injected">=</span><span class="operator injected"> </span><span class="operator injected">foo</span><span class="operator injected">.</span><span class="operator injected">bar</span><span class="operator injected"> </span><span class="operator injected">||</span><span class="operator injected"> </span><span class="operator injected">Foo</span><span class="operator injected">::</span><span class="operator injected">bar</span><span class="operator injected">;</span><span class="operator injected">
70 <span class="comment documentation">///</span> 70 </span><span class="comment documentation">///</span><span class="operator injected">
71 <span class="comment documentation">/// </span><span class="comment">/* multi-line 71</span> <span class="comment documentation">/// </span><span class="comment injected">/* multi-line
72 </span><span class="comment documentation">/// </span><span class="comment"> comment */</span> 72 </span><span class="comment documentation">/// </span><span class="comment injected"> comment */</span><span class="operator injected">
73 <span class="comment documentation">///</span> 73 </span><span class="comment documentation">///</span><span class="operator injected">
74 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">multi_line_string</span> = <span class="string_literal">"Foo 74</span> <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="operator injected"> </span><span class="operator injected">multi_line_string</span><span class="operator injected"> </span><span class="operator injected">=</span><span class="operator injected"> </span><span class="string_literal injected">"Foo
75 </span><span class="comment documentation">/// </span><span class="string_literal"> bar 75 </span><span class="comment documentation">/// </span><span class="string_literal injected"> bar
76 </span><span class="comment documentation">/// </span><span class="string_literal"> "</span>; 76 </span><span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="operator injected">;</span><span class="operator injected">
77 <span class="comment documentation">///</span> 77 </span><span class="comment documentation">///</span><span class="operator injected">
78 <span class="comment documentation">/// ```</span> 78</span> <span class="comment documentation">/// ```</span>
79 <span class="comment documentation">///</span> 79 <span class="comment documentation">///</span>
80 <span class="comment documentation">/// ```rust,no_run</span> 80 <span class="comment documentation">/// ```rust,no_run</span>
81 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">foobar</span> = <span class="struct">Foo</span>::<span class="function">new</span>().<span class="function">bar</span>(); 81 <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="operator injected"> </span><span class="operator injected">foobar</span><span class="operator injected"> </span><span class="operator injected">=</span><span class="operator injected"> </span><span class="operator injected">Foo</span><span class="operator injected">::</span><span class="operator injected">new</span><span class="operator injected">(</span><span class="operator injected">)</span><span class="operator injected">.</span><span class="operator injected">bar</span><span class="operator injected">(</span><span class="operator injected">)</span><span class="operator injected">;</span><span class="operator injected">
82 <span class="comment documentation">/// ```</span> 82</span><span class="operator injected"> </span> <span class="comment documentation">/// ```</span>
83 <span class="comment documentation">///</span> 83 <span class="comment documentation">///</span>
84 <span class="comment documentation">/// ```sh</span> 84 <span class="comment documentation">/// ```sh</span>
85 <span class="comment documentation">/// echo 1</span> 85 <span class="comment documentation">/// echo 1</span>
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 448645bdc..b4dcdba39 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -45,6 +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) -> Vec<HighlightedRange> { 49) -> Vec<HighlightedRange> {
49 let _p = profile("highlight"); 50 let _p = profile("highlight");
50 let sema = Semantics::new(db); 51 let sema = Semantics::new(db);
@@ -107,6 +108,7 @@ pub(crate) fn highlight(
107 &mut bindings_shadow_count, 108 &mut bindings_shadow_count,
108 syntactic_name_ref_highlighting, 109 syntactic_name_ref_highlighting,
109 name.syntax().clone().into(), 110 name.syntax().clone().into(),
111 default_tag,
110 ) { 112 ) {
111 stack.add(HighlightedRange { 113 stack.add(HighlightedRange {
112 range: name.syntax().text_range(), 114 range: name.syntax().text_range(),
@@ -206,6 +208,7 @@ pub(crate) fn highlight(
206 &mut bindings_shadow_count, 208 &mut bindings_shadow_count,
207 syntactic_name_ref_highlighting, 209 syntactic_name_ref_highlighting,
208 element_to_highlight.clone(), 210 element_to_highlight.clone(),
211 default_tag,
209 ) { 212 ) {
210 stack.add(HighlightedRange { range, highlight, binding_hash }); 213 stack.add(HighlightedRange { range, highlight, binding_hash });
211 if let Some(string) = 214 if let Some(string) =
@@ -430,13 +433,14 @@ fn highlight_element(
430 bindings_shadow_count: &mut FxHashMap<Name, u32>, 433 bindings_shadow_count: &mut FxHashMap<Name, u32>,
431 syntactic_name_ref_highlighting: bool, 434 syntactic_name_ref_highlighting: bool,
432 element: SyntaxElement, 435 element: SyntaxElement,
436 default_tag: Option<HighlightTag>,
433) -> Option<(Highlight, Option<u64>)> { 437) -> Option<(Highlight, Option<u64>)> {
434 let db = sema.db; 438 let db = sema.db;
435 let mut binding_hash = None; 439 let mut binding_hash = None;
436 let highlight: Highlight = match element.kind() { 440 let highlight: Highlight = match element.kind() {
437 FN_DEF => { 441 FN_DEF => {
438 bindings_shadow_count.clear(); 442 bindings_shadow_count.clear();
439 return None; 443 default_tag?.into()
440 } 444 }
441 445
442 // Highlight definitions depending on the "type" of the definition. 446 // Highlight definitions depending on the "type" of the definition.
@@ -515,12 +519,12 @@ fn highlight_element(
515 let expr = prefix_expr.expr()?; 519 let expr = prefix_expr.expr()?;
516 let ty = sema.type_of_expr(&expr)?; 520 let ty = sema.type_of_expr(&expr)?;
517 if !ty.is_raw_ptr() { 521 if !ty.is_raw_ptr() {
518 return None; 522 default_tag?.into()
523 } else {
524 let mut h = Highlight::new(HighlightTag::Operator);
525 h |= HighlightModifier::Unsafe;
526 h
519 } 527 }
520
521 let mut h = Highlight::new(HighlightTag::Operator);
522 h |= HighlightModifier::Unsafe;
523 h
524 } 528 }
525 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { 529 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
526 Highlight::new(HighlightTag::Macro) 530 Highlight::new(HighlightTag::Macro)
@@ -546,7 +550,7 @@ fn highlight_element(
546 } 550 }
547 } 551 }
548 552
549 _ => return None, 553 _ => default_tag?.into(),
550 }; 554 };
551 555
552 return Some((highlight, binding_hash)); 556 return Some((highlight, binding_hash));
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 99b6b25ab..9043024df 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -19,7 +19,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
19 ) 19 )
20 } 20 }
21 21
22 let ranges = highlight(db, file_id, None, false); 22 let ranges = highlight(db, file_id, None, false, None);
23 let text = parse.tree().syntax().to_string(); 23 let text = parse.tree().syntax().to_string();
24 let mut prev_pos = TextSize::from(0); 24 let mut prev_pos = TextSize::from(0);
25 let mut buf = String::new(); 25 let mut buf = String::new();
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 9d82b4009..bd38cdb6f 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -150,7 +150,10 @@ pub(super) fn highlight_doc_comment(
150 let (analysis, tmp_file_id) = Analysis::from_single_file(text); 150 let (analysis, tmp_file_id) = Analysis::from_single_file(text);
151 151
152 stack.push(); 152 stack.push();
153 for mut h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { 153 for mut h in analysis
154 .with_db(|db| super::highlight(db, tmp_file_id, None, true, Some(HighlightTag::Operator)))
155 .unwrap()
156 {
154 // Determine start offset and end offset in case of multi-line ranges 157 // Determine start offset and end offset in case of multi-line ranges
155 let mut start_offset = None; 158 let mut start_offset = None;
156 let mut end_offset = None; 159 let mut end_offset = None;
@@ -172,6 +175,7 @@ pub(super) fn highlight_doc_comment(
172 h.range.end() + end_offset.unwrap_or(start_offset) - h.range.start(), 175 h.range.end() + end_offset.unwrap_or(start_offset) - h.range.start(),
173 ); 176 );
174 177
178 h.highlight |= HighlightModifier::Injected;
175 stack.add(h); 179 stack.add(h);
176 } 180 }
177 } 181 }
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 93bbb4b4d..f5ab73865 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -57,6 +57,7 @@ pub enum HighlightModifier {
57 /// not. 57 /// not.
58 Definition, 58 Definition,
59 Documentation, 59 Documentation,
60 Injected,
60 Mutable, 61 Mutable,
61 Unsafe, 62 Unsafe,
62} 63}
@@ -110,6 +111,7 @@ impl HighlightModifier {
110 HighlightModifier::ControlFlow, 111 HighlightModifier::ControlFlow,
111 HighlightModifier::Definition, 112 HighlightModifier::Definition,
112 HighlightModifier::Documentation, 113 HighlightModifier::Documentation,
114 HighlightModifier::Injected,
113 HighlightModifier::Mutable, 115 HighlightModifier::Mutable,
114 HighlightModifier::Unsafe, 116 HighlightModifier::Unsafe,
115 ]; 117 ];
@@ -120,6 +122,7 @@ impl HighlightModifier {
120 HighlightModifier::ControlFlow => "control", 122 HighlightModifier::ControlFlow => "control",
121 HighlightModifier::Definition => "declaration", 123 HighlightModifier::Definition => "declaration",
122 HighlightModifier::Documentation => "documentation", 124 HighlightModifier::Documentation => "documentation",
125 HighlightModifier::Injected => "injected",
123 HighlightModifier::Mutable => "mutable", 126 HighlightModifier::Mutable => "mutable",
124 HighlightModifier::Unsafe => "unsafe", 127 HighlightModifier::Unsafe => "unsafe",
125 } 128 }
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index 2ea63d33b..6f43667a3 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -68,6 +68,7 @@ macro_rules! define_semantic_token_modifiers {
68define_semantic_token_modifiers![ 68define_semantic_token_modifiers![
69 (CONSTANT, "constant"), 69 (CONSTANT, "constant"),
70 (CONTROL_FLOW, "controlFlow"), 70 (CONTROL_FLOW, "controlFlow"),
71 (INJECTED, "injected"),
71 (MUTABLE, "mutable"), 72 (MUTABLE, "mutable"),
72 (UNSAFE, "unsafe"), 73 (UNSAFE, "unsafe"),
73 (ATTRIBUTE_MODIFIER, "attribute"), 74 (ATTRIBUTE_MODIFIER, "attribute"),
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 7b45b169d..dee5d7859 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -331,6 +331,7 @@ fn semantic_token_type_and_modifiers(
331 HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER, 331 HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER,
332 HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION, 332 HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
333 HighlightModifier::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION, 333 HighlightModifier::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION,
334 HighlightModifier::Injected => semantic_tokens::INJECTED,
334 HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW, 335 HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW,
335 HighlightModifier::Mutable => semantic_tokens::MUTABLE, 336 HighlightModifier::Mutable => semantic_tokens::MUTABLE,
336 HighlightModifier::Unsafe => semantic_tokens::UNSAFE, 337 HighlightModifier::Unsafe => semantic_tokens::UNSAFE,