diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
-rw-r--r-- | crates/ide/src/syntax_highlighting/format.rs | 12 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlights.rs | 61 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/html.rs | 16 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injection.rs | 105 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injector.rs | 12 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/macro_rules.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 138 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html | 20 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/injection.html | 4 |
9 files changed, 169 insertions, 207 deletions
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index ab66b406c..d807ad0ad 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs | |||
@@ -4,7 +4,7 @@ use syntax::{ | |||
4 | AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, | 4 | AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::{HighlightTag, HighlightedRange, SymbolKind}; | 7 | use crate::{HlRange, HlTag, SymbolKind}; |
8 | 8 | ||
9 | use super::highlights::Highlights; | 9 | use super::highlights::Highlights; |
10 | 10 | ||
@@ -46,7 +46,7 @@ impl FormatStringHighlighter { | |||
46 | if self.format_string.as_ref() == Some(&SyntaxElement::from(string.syntax().clone())) { | 46 | if self.format_string.as_ref() == Some(&SyntaxElement::from(string.syntax().clone())) { |
47 | string.lex_format_specifier(|piece_range, kind| { | 47 | string.lex_format_specifier(|piece_range, kind| { |
48 | if let Some(highlight) = highlight_format_specifier(kind) { | 48 | if let Some(highlight) = highlight_format_specifier(kind) { |
49 | stack.add(HighlightedRange { | 49 | stack.add(HlRange { |
50 | range: piece_range + range.start(), | 50 | range: piece_range + range.start(), |
51 | highlight: highlight.into(), | 51 | highlight: highlight.into(), |
52 | binding_hash: None, | 52 | binding_hash: None, |
@@ -57,7 +57,7 @@ impl FormatStringHighlighter { | |||
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { | 60 | fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HlTag> { |
61 | Some(match kind { | 61 | Some(match kind { |
62 | FormatSpecifier::Open | 62 | FormatSpecifier::Open |
63 | | FormatSpecifier::Close | 63 | | FormatSpecifier::Close |
@@ -69,8 +69,8 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> { | |||
69 | | FormatSpecifier::DollarSign | 69 | | FormatSpecifier::DollarSign |
70 | | FormatSpecifier::Dot | 70 | | FormatSpecifier::Dot |
71 | | FormatSpecifier::Asterisk | 71 | | FormatSpecifier::Asterisk |
72 | | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, | 72 | | FormatSpecifier::QuestionMark => HlTag::FormatSpecifier, |
73 | FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, | 73 | FormatSpecifier::Integer | FormatSpecifier::Zero => HlTag::NumericLiteral, |
74 | FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local), | 74 | FormatSpecifier::Identifier => HlTag::Symbol(SymbolKind::Local), |
75 | }) | 75 | }) |
76 | } | 76 | } |
diff --git a/crates/ide/src/syntax_highlighting/highlights.rs b/crates/ide/src/syntax_highlighting/highlights.rs index 3e733c87c..11c11ed28 100644 --- a/crates/ide/src/syntax_highlighting/highlights.rs +++ b/crates/ide/src/syntax_highlighting/highlights.rs | |||
@@ -4,33 +4,29 @@ use std::{cmp::Ordering, iter}; | |||
4 | use stdx::equal_range_by; | 4 | use stdx::equal_range_by; |
5 | use syntax::TextRange; | 5 | use syntax::TextRange; |
6 | 6 | ||
7 | use crate::{HighlightTag, HighlightedRange}; | 7 | use crate::{HlRange, HlTag}; |
8 | 8 | ||
9 | pub(super) struct Highlights { | 9 | pub(super) struct Highlights { |
10 | root: Node, | 10 | root: Node, |
11 | } | 11 | } |
12 | 12 | ||
13 | struct Node { | 13 | struct Node { |
14 | highlighted_range: HighlightedRange, | 14 | hl_range: HlRange, |
15 | nested: Vec<Node>, | 15 | nested: Vec<Node>, |
16 | } | 16 | } |
17 | 17 | ||
18 | impl Highlights { | 18 | impl Highlights { |
19 | pub(super) fn new(range: TextRange) -> Highlights { | 19 | pub(super) fn new(range: TextRange) -> Highlights { |
20 | Highlights { | 20 | Highlights { |
21 | root: Node::new(HighlightedRange { | 21 | root: Node::new(HlRange { range, highlight: HlTag::None.into(), binding_hash: None }), |
22 | range, | ||
23 | highlight: HighlightTag::Dummy.into(), | ||
24 | binding_hash: None, | ||
25 | }), | ||
26 | } | 22 | } |
27 | } | 23 | } |
28 | 24 | ||
29 | pub(super) fn add(&mut self, highlighted_range: HighlightedRange) { | 25 | pub(super) fn add(&mut self, hl_range: HlRange) { |
30 | self.root.add(highlighted_range); | 26 | self.root.add(hl_range); |
31 | } | 27 | } |
32 | 28 | ||
33 | pub(super) fn to_vec(self) -> Vec<HighlightedRange> { | 29 | pub(super) fn to_vec(self) -> Vec<HlRange> { |
34 | let mut res = Vec::new(); | 30 | let mut res = Vec::new(); |
35 | self.root.flatten(&mut res); | 31 | self.root.flatten(&mut res); |
36 | res | 32 | res |
@@ -38,59 +34,54 @@ impl Highlights { | |||
38 | } | 34 | } |
39 | 35 | ||
40 | impl Node { | 36 | impl Node { |
41 | fn new(highlighted_range: HighlightedRange) -> Node { | 37 | fn new(hl_range: HlRange) -> Node { |
42 | Node { highlighted_range, nested: Vec::new() } | 38 | Node { hl_range, nested: Vec::new() } |
43 | } | 39 | } |
44 | 40 | ||
45 | fn add(&mut self, highlighted_range: HighlightedRange) { | 41 | fn add(&mut self, hl_range: HlRange) { |
46 | assert!(self.highlighted_range.range.contains_range(highlighted_range.range)); | 42 | assert!(self.hl_range.range.contains_range(hl_range.range)); |
47 | 43 | ||
48 | // Fast path | 44 | // Fast path |
49 | if let Some(last) = self.nested.last_mut() { | 45 | if let Some(last) = self.nested.last_mut() { |
50 | if last.highlighted_range.range.contains_range(highlighted_range.range) { | 46 | if last.hl_range.range.contains_range(hl_range.range) { |
51 | return last.add(highlighted_range); | 47 | return last.add(hl_range); |
52 | } | 48 | } |
53 | if last.highlighted_range.range.end() <= highlighted_range.range.start() { | 49 | if last.hl_range.range.end() <= hl_range.range.start() { |
54 | return self.nested.push(Node::new(highlighted_range)); | 50 | return self.nested.push(Node::new(hl_range)); |
55 | } | 51 | } |
56 | } | 52 | } |
57 | 53 | ||
58 | let (start, len) = equal_range_by(&self.nested, |n| { | 54 | let (start, len) = |
59 | ordering(n.highlighted_range.range, highlighted_range.range) | 55 | equal_range_by(&self.nested, |n| ordering(n.hl_range.range, hl_range.range)); |
60 | }); | ||
61 | 56 | ||
62 | if len == 1 | 57 | if len == 1 && self.nested[start].hl_range.range.contains_range(hl_range.range) { |
63 | && self.nested[start].highlighted_range.range.contains_range(highlighted_range.range) | 58 | return self.nested[start].add(hl_range); |
64 | { | ||
65 | return self.nested[start].add(highlighted_range); | ||
66 | } | 59 | } |
67 | 60 | ||
68 | let nested = self | 61 | let nested = self |
69 | .nested | 62 | .nested |
70 | .splice(start..start + len, iter::once(Node::new(highlighted_range))) | 63 | .splice(start..start + len, iter::once(Node::new(hl_range))) |
71 | .collect::<Vec<_>>(); | 64 | .collect::<Vec<_>>(); |
72 | self.nested[start].nested = nested; | 65 | self.nested[start].nested = nested; |
73 | } | 66 | } |
74 | 67 | ||
75 | fn flatten(&self, acc: &mut Vec<HighlightedRange>) { | 68 | fn flatten(&self, acc: &mut Vec<HlRange>) { |
76 | let mut start = self.highlighted_range.range.start(); | 69 | let mut start = self.hl_range.range.start(); |
77 | let mut nested = self.nested.iter(); | 70 | let mut nested = self.nested.iter(); |
78 | loop { | 71 | loop { |
79 | let next = nested.next(); | 72 | let next = nested.next(); |
80 | let end = next.map_or(self.highlighted_range.range.end(), |it| { | 73 | let end = next.map_or(self.hl_range.range.end(), |it| it.hl_range.range.start()); |
81 | it.highlighted_range.range.start() | ||
82 | }); | ||
83 | if start < end { | 74 | if start < end { |
84 | acc.push(HighlightedRange { | 75 | acc.push(HlRange { |
85 | range: TextRange::new(start, end), | 76 | range: TextRange::new(start, end), |
86 | highlight: self.highlighted_range.highlight, | 77 | highlight: self.hl_range.highlight, |
87 | binding_hash: self.highlighted_range.binding_hash, | 78 | binding_hash: self.hl_range.binding_hash, |
88 | }); | 79 | }); |
89 | } | 80 | } |
90 | start = match next { | 81 | start = match next { |
91 | Some(child) => { | 82 | Some(child) => { |
92 | child.flatten(acc); | 83 | child.flatten(acc); |
93 | child.highlighted_range.range.end() | 84 | child.hl_range.range.end() |
94 | } | 85 | } |
95 | None => break, | 86 | None => break, |
96 | } | 87 | } |
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 44f611b25..0ee7bc96e 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -20,26 +20,26 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
20 | ) | 20 | ) |
21 | } | 21 | } |
22 | 22 | ||
23 | let ranges = highlight(db, file_id, None, false); | 23 | let hl_ranges = highlight(db, file_id, None, false); |
24 | let text = parse.tree().syntax().to_string(); | 24 | let text = parse.tree().syntax().to_string(); |
25 | let mut buf = String::new(); | 25 | let mut buf = String::new(); |
26 | buf.push_str(&STYLE); | 26 | buf.push_str(&STYLE); |
27 | buf.push_str("<pre><code>"); | 27 | buf.push_str("<pre><code>"); |
28 | for range in &ranges { | 28 | for r in &hl_ranges { |
29 | let curr = &text[range.range]; | 29 | let chunk = html_escape(&text[r.range]); |
30 | if range.highlight.is_empty() { | 30 | if r.highlight.is_empty() { |
31 | format_to!(buf, "{}", html_escape(curr)); | 31 | format_to!(buf, "{}", chunk); |
32 | continue; | 32 | continue; |
33 | } | 33 | } |
34 | 34 | ||
35 | let class = range.highlight.to_string().replace('.', " "); | 35 | let class = r.highlight.to_string().replace('.', " "); |
36 | let color = match (rainbow, range.binding_hash) { | 36 | let color = match (rainbow, r.binding_hash) { |
37 | (true, Some(hash)) => { | 37 | (true, Some(hash)) => { |
38 | format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) | 38 | format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash)) |
39 | } | 39 | } |
40 | _ => "".into(), | 40 | _ => "".into(), |
41 | }; | 41 | }; |
42 | format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, html_escape(curr)); | 42 | format_to!(buf, "<span class=\"{}\"{}>{}</span>", class, color, chunk); |
43 | } | 43 | } |
44 | buf.push_str("</code></pre>"); | 44 | buf.push_str("</code></pre>"); |
45 | buf | 45 | buf |
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index 98ee03e0d..008d5ce24 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs | |||
@@ -7,12 +7,12 @@ 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, HighlightModifier, HighlightTag, HighlightedRange, 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 | ||
14 | pub(super) fn highlight_injection( | 14 | pub(super) fn highlight_injection( |
15 | acc: &mut Highlights, | 15 | hl: &mut Highlights, |
16 | sema: &Semantics<RootDatabase>, | 16 | sema: &Semantics<RootDatabase>, |
17 | literal: ast::String, | 17 | literal: ast::String, |
18 | expanded: SyntaxToken, | 18 | expanded: SyntaxToken, |
@@ -22,80 +22,53 @@ pub(super) fn highlight_injection( | |||
22 | return None; | 22 | return None; |
23 | } | 23 | } |
24 | let value = literal.value()?; | 24 | let value = literal.value()?; |
25 | let marker_info = MarkerInfo::new(&*value); | ||
26 | let (analysis, tmp_file_id) = Analysis::from_single_file(marker_info.cleaned_text.clone()); | ||
27 | 25 | ||
28 | if let Some(range) = literal.open_quote_text_range() { | 26 | if let Some(range) = literal.open_quote_text_range() { |
29 | acc.add(HighlightedRange { | 27 | hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) |
30 | range, | ||
31 | highlight: HighlightTag::StringLiteral.into(), | ||
32 | binding_hash: None, | ||
33 | }) | ||
34 | } | 28 | } |
35 | 29 | ||
36 | for mut h in analysis.highlight(tmp_file_id).unwrap() { | 30 | let mut inj = Injector::default(); |
37 | let range = marker_info.map_range_up(h.range); | ||
38 | if let Some(range) = literal.map_range_up(range) { | ||
39 | h.range = range; | ||
40 | acc.add(h); | ||
41 | } | ||
42 | } | ||
43 | 31 | ||
44 | if let Some(range) = literal.close_quote_text_range() { | 32 | let mut text = &*value; |
45 | acc.add(HighlightedRange { | 33 | let mut offset: TextSize = 0.into(); |
46 | range, | ||
47 | highlight: HighlightTag::StringLiteral.into(), | ||
48 | binding_hash: None, | ||
49 | }) | ||
50 | } | ||
51 | 34 | ||
52 | Some(()) | 35 | while !text.is_empty() { |
53 | } | 36 | let marker = "$0"; |
37 | let idx = text.find(marker).unwrap_or(text.len()); | ||
38 | let (chunk, next) = text.split_at(idx); | ||
39 | inj.add(chunk, TextRange::at(offset, TextSize::of(chunk))); | ||
54 | 40 | ||
55 | /// Data to remove `$0` from string and map ranges | 41 | text = next; |
56 | #[derive(Default, Debug)] | 42 | offset += TextSize::of(chunk); |
57 | struct MarkerInfo { | ||
58 | cleaned_text: String, | ||
59 | markers: Vec<TextRange>, | ||
60 | } | ||
61 | 43 | ||
62 | impl MarkerInfo { | 44 | if let Some(next) = text.strip_prefix(marker) { |
63 | fn new(mut text: &str) -> Self { | 45 | if let Some(range) = literal.map_range_up(TextRange::at(offset, TextSize::of(marker))) { |
64 | let marker = "$0"; | 46 | hl.add(HlRange { range, highlight: HlTag::Keyword.into(), binding_hash: None }); |
47 | } | ||
65 | 48 | ||
66 | let mut res = MarkerInfo::default(); | ||
67 | let mut offset: TextSize = 0.into(); | ||
68 | while !text.is_empty() { | ||
69 | let idx = text.find(marker).unwrap_or(text.len()); | ||
70 | let (chunk, next) = text.split_at(idx); | ||
71 | text = next; | 49 | text = next; |
72 | res.cleaned_text.push_str(chunk); | ||
73 | offset += TextSize::of(chunk); | ||
74 | |||
75 | if let Some(next) = text.strip_prefix(marker) { | ||
76 | text = next; | ||
77 | 50 | ||
78 | let marker_len = TextSize::of(marker); | 51 | let marker_len = TextSize::of(marker); |
79 | res.markers.push(TextRange::at(offset, marker_len)); | 52 | offset += marker_len; |
80 | offset += marker_len; | ||
81 | } | ||
82 | } | 53 | } |
83 | res | ||
84 | } | 54 | } |
85 | fn map_range_up(&self, range: TextRange) -> TextRange { | 55 | |
86 | TextRange::new( | 56 | let (analysis, tmp_file_id) = Analysis::from_single_file(inj.text().to_string()); |
87 | self.map_offset_up(range.start(), true), | 57 | |
88 | self.map_offset_up(range.end(), false), | 58 | for mut hl_range in analysis.highlight(tmp_file_id).unwrap() { |
89 | ) | 59 | for range in inj.map_range_up(hl_range.range) { |
90 | } | 60 | if let Some(range) = literal.map_range_up(range) { |
91 | fn map_offset_up(&self, mut offset: TextSize, start: bool) -> TextSize { | 61 | hl_range.range = range; |
92 | for r in &self.markers { | 62 | hl.add(hl_range.clone()); |
93 | if r.start() < offset || (start && r.start() == offset) { | ||
94 | offset += r.len() | ||
95 | } | 63 | } |
96 | } | 64 | } |
97 | offset | ||
98 | } | 65 | } |
66 | |||
67 | if let Some(range) = literal.close_quote_text_range() { | ||
68 | hl.add(HlRange { range, highlight: HlTag::StringLiteral.into(), binding_hash: None }) | ||
69 | } | ||
70 | |||
71 | Some(()) | ||
99 | } | 72 | } |
100 | 73 | ||
101 | const RUSTDOC_FENCE: &'static str = "```"; | 74 | const RUSTDOC_FENCE: &'static str = "```"; |
@@ -116,7 +89,7 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[ | |||
116 | /// Lastly, a vector of new comment highlight ranges (spanning only the | 89 | /// Lastly, a vector of new comment highlight ranges (spanning only the |
117 | /// comment prefix) is returned which is used in the syntax highlighting | 90 | /// comment prefix) is returned which is used in the syntax highlighting |
118 | /// injection to replace the previous (line-spanning) comment ranges. | 91 | /// injection to replace the previous (line-spanning) comment ranges. |
119 | pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HighlightedRange>, Injector)> { | 92 | pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<HlRange>, Injector)> { |
120 | let mut inj = Injector::default(); | 93 | let mut inj = Injector::default(); |
121 | // wrap the doctest into function body to get correct syntax highlighting | 94 | // wrap the doctest into function body to get correct syntax highlighting |
122 | let prefix = "fn doctest() {\n"; | 95 | let prefix = "fn doctest() {\n"; |
@@ -166,12 +139,12 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted | |||
166 | pos | 139 | pos |
167 | }; | 140 | }; |
168 | 141 | ||
169 | new_comments.push(HighlightedRange { | 142 | new_comments.push(HlRange { |
170 | range: TextRange::new( | 143 | range: TextRange::new( |
171 | range.start(), | 144 | range.start(), |
172 | range.start() + TextSize::try_from(pos).unwrap(), | 145 | range.start() + TextSize::try_from(pos).unwrap(), |
173 | ), | 146 | ), |
174 | highlight: HighlightTag::Comment | HighlightModifier::Documentation, | 147 | highlight: HlTag::Comment | HlMod::Documentation, |
175 | binding_hash: None, | 148 | binding_hash: None, |
176 | }); | 149 | }); |
177 | line_start += range.len() - TextSize::try_from(pos).unwrap(); | 150 | line_start += range.len() - TextSize::try_from(pos).unwrap(); |
@@ -196,7 +169,7 @@ pub(super) fn extract_doc_comments(node: &SyntaxNode) -> Option<(Vec<Highlighted | |||
196 | 169 | ||
197 | /// Injection of syntax highlighting of doctests. | 170 | /// Injection of syntax highlighting of doctests. |
198 | pub(super) fn highlight_doc_comment( | 171 | pub(super) fn highlight_doc_comment( |
199 | new_comments: Vec<HighlightedRange>, | 172 | new_comments: Vec<HlRange>, |
200 | inj: Injector, | 173 | inj: Injector, |
201 | stack: &mut Highlights, | 174 | stack: &mut Highlights, |
202 | ) { | 175 | ) { |
@@ -207,9 +180,9 @@ pub(super) fn highlight_doc_comment( | |||
207 | 180 | ||
208 | for h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { | 181 | 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) { | 182 | for r in inj.map_range_up(h.range) { |
210 | stack.add(HighlightedRange { | 183 | stack.add(HlRange { |
211 | range: r, | 184 | range: r, |
212 | highlight: h.highlight | HighlightModifier::Injected, | 185 | highlight: h.highlight | HlMod::Injected, |
213 | binding_hash: h.binding_hash, | 186 | binding_hash: h.binding_hash, |
214 | }); | 187 | }); |
215 | } | 188 | } |
diff --git a/crates/ide/src/syntax_highlighting/injector.rs b/crates/ide/src/syntax_highlighting/injector.rs index 0513a9fd6..e8f17eb69 100644 --- a/crates/ide/src/syntax_highlighting/injector.rs +++ b/crates/ide/src/syntax_highlighting/injector.rs | |||
@@ -17,17 +17,15 @@ impl Injector { | |||
17 | pub(super) fn add(&mut self, text: &str, source_range: TextRange) { | 17 | pub(super) fn add(&mut self, text: &str, source_range: TextRange) { |
18 | let len = TextSize::of(text); | 18 | let len = TextSize::of(text); |
19 | assert_eq!(len, source_range.len()); | 19 | assert_eq!(len, source_range.len()); |
20 | 20 | self.add_impl(text, Some(source_range.start())); | |
21 | let target_range = TextRange::at(TextSize::of(&self.buf), len); | ||
22 | self.ranges | ||
23 | .push((target_range, Some(Delta::new(target_range.start(), source_range.start())))); | ||
24 | self.buf.push_str(text); | ||
25 | } | 21 | } |
26 | pub(super) fn add_unmapped(&mut self, text: &str) { | 22 | pub(super) fn add_unmapped(&mut self, text: &str) { |
23 | self.add_impl(text, None); | ||
24 | } | ||
25 | fn add_impl(&mut self, text: &str, source: Option<TextSize>) { | ||
27 | let len = TextSize::of(text); | 26 | let len = TextSize::of(text); |
28 | |||
29 | let target_range = TextRange::at(TextSize::of(&self.buf), len); | 27 | let target_range = TextRange::at(TextSize::of(&self.buf), len); |
30 | self.ranges.push((target_range, None)); | 28 | self.ranges.push((target_range, source.map(|it| Delta::new(target_range.start(), it)))); |
31 | self.buf.push_str(text); | 29 | self.buf.push_str(text); |
32 | } | 30 | } |
33 | 31 | ||
diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs index 4462af47e..21d8a9835 100644 --- a/crates/ide/src/syntax_highlighting/macro_rules.rs +++ b/crates/ide/src/syntax_highlighting/macro_rules.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Syntax highlighting for macro_rules!. | 1 | //! Syntax highlighting for macro_rules!. |
2 | use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; | 2 | use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; |
3 | 3 | ||
4 | use crate::{HighlightTag, HighlightedRange}; | 4 | use crate::{HlRange, HlTag}; |
5 | 5 | ||
6 | #[derive(Default)] | 6 | #[derive(Default)] |
7 | pub(super) struct MacroRulesHighlighter { | 7 | pub(super) struct MacroRulesHighlighter { |
@@ -19,13 +19,13 @@ impl MacroRulesHighlighter { | |||
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | pub(super) fn highlight(&self, element: SyntaxElement) -> Option<HighlightedRange> { | 22 | pub(super) fn highlight(&self, element: SyntaxElement) -> Option<HlRange> { |
23 | if let Some(state) = self.state.as_ref() { | 23 | if let Some(state) = self.state.as_ref() { |
24 | if matches!(state.rule_state, RuleState::Matcher | RuleState::Expander) { | 24 | if matches!(state.rule_state, RuleState::Matcher | RuleState::Expander) { |
25 | if let Some(range) = is_metavariable(element) { | 25 | if let Some(range) = is_metavariable(element) { |
26 | return Some(HighlightedRange { | 26 | return Some(HlRange { |
27 | range, | 27 | range, |
28 | highlight: HighlightTag::UnresolvedReference.into(), | 28 | highlight: HlTag::UnresolvedReference.into(), |
29 | binding_hash: None, | 29 | binding_hash: None, |
30 | }); | 30 | }); |
31 | } | 31 | } |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index a0286b72d..2f39bcc8e 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -7,15 +7,15 @@ use crate::SymbolKind; | |||
7 | 7 | ||
8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 8 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
9 | pub struct Highlight { | 9 | pub struct Highlight { |
10 | pub tag: HighlightTag, | 10 | pub tag: HlTag, |
11 | pub modifiers: HighlightModifiers, | 11 | pub mods: HlMods, |
12 | } | 12 | } |
13 | 13 | ||
14 | #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 14 | #[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
15 | pub struct HighlightModifiers(u32); | 15 | pub struct HlMods(u32); |
16 | 16 | ||
17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 17 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
18 | pub enum HighlightTag { | 18 | pub enum HlTag { |
19 | Symbol(SymbolKind), | 19 | Symbol(SymbolKind), |
20 | 20 | ||
21 | BoolLiteral, | 21 | BoolLiteral, |
@@ -33,13 +33,13 @@ pub enum HighlightTag { | |||
33 | Operator, | 33 | Operator, |
34 | UnresolvedReference, | 34 | UnresolvedReference, |
35 | 35 | ||
36 | // For things which don't have proper Tag, but want to use modifiers. | 36 | // For things which don't have a specific highlight. |
37 | Dummy, | 37 | None, |
38 | } | 38 | } |
39 | 39 | ||
40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
41 | #[repr(u8)] | 41 | #[repr(u8)] |
42 | pub enum HighlightModifier { | 42 | pub enum HlMod { |
43 | /// Used to differentiate individual elements within attributes. | 43 | /// Used to differentiate individual elements within attributes. |
44 | Attribute = 0, | 44 | Attribute = 0, |
45 | /// Used with keywords like `if` and `break`. | 45 | /// Used with keywords like `if` and `break`. |
@@ -61,10 +61,10 @@ pub enum HighlightModifier { | |||
61 | Unsafe, | 61 | Unsafe, |
62 | } | 62 | } |
63 | 63 | ||
64 | impl HighlightTag { | 64 | impl HlTag { |
65 | fn as_str(self) -> &'static str { | 65 | fn as_str(self) -> &'static str { |
66 | match self { | 66 | match self { |
67 | HighlightTag::Symbol(symbol) => match symbol { | 67 | HlTag::Symbol(symbol) => match symbol { |
68 | SymbolKind::Const => "constant", | 68 | SymbolKind::Const => "constant", |
69 | SymbolKind::Static => "static", | 69 | SymbolKind::Static => "static", |
70 | SymbolKind::Enum => "enum", | 70 | SymbolKind::Enum => "enum", |
@@ -86,59 +86,59 @@ impl HighlightTag { | |||
86 | SymbolKind::SelfParam => "self_keyword", | 86 | SymbolKind::SelfParam => "self_keyword", |
87 | SymbolKind::Impl => "self_type", | 87 | SymbolKind::Impl => "self_type", |
88 | }, | 88 | }, |
89 | HighlightTag::Attribute => "attribute", | 89 | HlTag::Attribute => "attribute", |
90 | HighlightTag::BoolLiteral => "bool_literal", | 90 | HlTag::BoolLiteral => "bool_literal", |
91 | HighlightTag::BuiltinType => "builtin_type", | 91 | HlTag::BuiltinType => "builtin_type", |
92 | HighlightTag::ByteLiteral => "byte_literal", | 92 | HlTag::ByteLiteral => "byte_literal", |
93 | HighlightTag::CharLiteral => "char_literal", | 93 | HlTag::CharLiteral => "char_literal", |
94 | HighlightTag::Comment => "comment", | 94 | HlTag::Comment => "comment", |
95 | HighlightTag::EscapeSequence => "escape_sequence", | 95 | HlTag::EscapeSequence => "escape_sequence", |
96 | HighlightTag::FormatSpecifier => "format_specifier", | 96 | HlTag::FormatSpecifier => "format_specifier", |
97 | HighlightTag::Keyword => "keyword", | 97 | HlTag::Keyword => "keyword", |
98 | HighlightTag::Punctuation => "punctuation", | 98 | HlTag::Punctuation => "punctuation", |
99 | HighlightTag::NumericLiteral => "numeric_literal", | 99 | HlTag::NumericLiteral => "numeric_literal", |
100 | HighlightTag::Operator => "operator", | 100 | HlTag::Operator => "operator", |
101 | HighlightTag::StringLiteral => "string_literal", | 101 | HlTag::StringLiteral => "string_literal", |
102 | HighlightTag::UnresolvedReference => "unresolved_reference", | 102 | HlTag::UnresolvedReference => "unresolved_reference", |
103 | HighlightTag::Dummy => "dummy", | 103 | HlTag::None => "none", |
104 | } | 104 | } |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | impl fmt::Display for HighlightTag { | 108 | impl fmt::Display for HlTag { |
109 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 109 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
110 | fmt::Display::fmt(self.as_str(), f) | 110 | fmt::Display::fmt(self.as_str(), f) |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | impl HighlightModifier { | 114 | impl HlMod { |
115 | const ALL: &'static [HighlightModifier; HighlightModifier::Unsafe as u8 as usize + 1] = &[ | 115 | const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[ |
116 | HighlightModifier::Attribute, | 116 | HlMod::Attribute, |
117 | HighlightModifier::ControlFlow, | 117 | HlMod::ControlFlow, |
118 | HighlightModifier::Definition, | 118 | HlMod::Definition, |
119 | HighlightModifier::Documentation, | 119 | HlMod::Documentation, |
120 | HighlightModifier::Injected, | 120 | HlMod::Injected, |
121 | HighlightModifier::Mutable, | 121 | HlMod::Mutable, |
122 | HighlightModifier::Consuming, | 122 | HlMod::Consuming, |
123 | HighlightModifier::Callable, | 123 | HlMod::Callable, |
124 | HighlightModifier::Static, | 124 | HlMod::Static, |
125 | HighlightModifier::Associated, | 125 | HlMod::Associated, |
126 | HighlightModifier::Unsafe, | 126 | HlMod::Unsafe, |
127 | ]; | 127 | ]; |
128 | 128 | ||
129 | fn as_str(self) -> &'static str { | 129 | fn as_str(self) -> &'static str { |
130 | match self { | 130 | match self { |
131 | HighlightModifier::Attribute => "attribute", | 131 | HlMod::Attribute => "attribute", |
132 | HighlightModifier::ControlFlow => "control", | 132 | HlMod::ControlFlow => "control", |
133 | HighlightModifier::Definition => "declaration", | 133 | HlMod::Definition => "declaration", |
134 | HighlightModifier::Documentation => "documentation", | 134 | HlMod::Documentation => "documentation", |
135 | HighlightModifier::Injected => "injected", | 135 | HlMod::Injected => "injected", |
136 | HighlightModifier::Mutable => "mutable", | 136 | HlMod::Mutable => "mutable", |
137 | HighlightModifier::Consuming => "consuming", | 137 | HlMod::Consuming => "consuming", |
138 | HighlightModifier::Unsafe => "unsafe", | 138 | HlMod::Unsafe => "unsafe", |
139 | HighlightModifier::Callable => "callable", | 139 | HlMod::Callable => "callable", |
140 | HighlightModifier::Static => "static", | 140 | HlMod::Static => "static", |
141 | HighlightModifier::Associated => "associated", | 141 | HlMod::Associated => "associated", |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
@@ -147,7 +147,7 @@ impl HighlightModifier { | |||
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | impl fmt::Display for HighlightModifier { | 150 | impl fmt::Display for HlMod { |
151 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 151 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
152 | fmt::Display::fmt(self.as_str(), f) | 152 | fmt::Display::fmt(self.as_str(), f) |
153 | } | 153 | } |
@@ -156,63 +156,63 @@ impl fmt::Display for HighlightModifier { | |||
156 | impl fmt::Display for Highlight { | 156 | impl fmt::Display for Highlight { |
157 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 157 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
158 | write!(f, "{}", self.tag)?; | 158 | write!(f, "{}", self.tag)?; |
159 | for modifier in self.modifiers.iter() { | 159 | for modifier in self.mods.iter() { |
160 | write!(f, ".{}", modifier)? | 160 | write!(f, ".{}", modifier)? |
161 | } | 161 | } |
162 | Ok(()) | 162 | Ok(()) |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | impl From<HighlightTag> for Highlight { | 166 | impl From<HlTag> for Highlight { |
167 | fn from(tag: HighlightTag) -> Highlight { | 167 | fn from(tag: HlTag) -> Highlight { |
168 | Highlight::new(tag) | 168 | Highlight::new(tag) |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
172 | impl Highlight { | 172 | impl Highlight { |
173 | pub(crate) fn new(tag: HighlightTag) -> Highlight { | 173 | pub(crate) fn new(tag: HlTag) -> Highlight { |
174 | Highlight { tag, modifiers: HighlightModifiers::default() } | 174 | Highlight { tag, mods: HlMods::default() } |
175 | } | 175 | } |
176 | pub fn is_empty(&self) -> bool { | 176 | pub fn is_empty(&self) -> bool { |
177 | self.tag == HighlightTag::Dummy && self.modifiers == HighlightModifiers::default() | 177 | self.tag == HlTag::None && self.mods == HlMods::default() |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | impl ops::BitOr<HighlightModifier> for HighlightTag { | 181 | impl ops::BitOr<HlMod> for HlTag { |
182 | type Output = Highlight; | 182 | type Output = Highlight; |
183 | 183 | ||
184 | fn bitor(self, rhs: HighlightModifier) -> Highlight { | 184 | fn bitor(self, rhs: HlMod) -> Highlight { |
185 | Highlight::new(self) | rhs | 185 | Highlight::new(self) | rhs |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | impl ops::BitOrAssign<HighlightModifier> for HighlightModifiers { | 189 | impl ops::BitOrAssign<HlMod> for HlMods { |
190 | fn bitor_assign(&mut self, rhs: HighlightModifier) { | 190 | fn bitor_assign(&mut self, rhs: HlMod) { |
191 | self.0 |= rhs.mask(); | 191 | self.0 |= rhs.mask(); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | impl ops::BitOrAssign<HighlightModifier> for Highlight { | 195 | impl ops::BitOrAssign<HlMod> for Highlight { |
196 | fn bitor_assign(&mut self, rhs: HighlightModifier) { | 196 | fn bitor_assign(&mut self, rhs: HlMod) { |
197 | self.modifiers |= rhs; | 197 | self.mods |= rhs; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | impl ops::BitOr<HighlightModifier> for Highlight { | 201 | impl ops::BitOr<HlMod> for Highlight { |
202 | type Output = Highlight; | 202 | type Output = Highlight; |
203 | 203 | ||
204 | fn bitor(mut self, rhs: HighlightModifier) -> Highlight { | 204 | fn bitor(mut self, rhs: HlMod) -> Highlight { |
205 | self |= rhs; | 205 | self |= rhs; |
206 | self | 206 | self |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | impl HighlightModifiers { | 210 | impl HlMods { |
211 | pub fn contains(self, m: HighlightModifier) -> bool { | 211 | pub fn contains(self, m: HlMod) -> bool { |
212 | self.0 & m.mask() == m.mask() | 212 | self.0 & m.mask() == m.mask() |
213 | } | 213 | } |
214 | 214 | ||
215 | pub fn iter(self) -> impl Iterator<Item = HighlightModifier> { | 215 | pub fn iter(self) -> impl Iterator<Item = HlMod> { |
216 | HighlightModifier::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask()) | 216 | HlMod::ALL.iter().copied().filter(move |it| self.0 & it.mask() == it.mask()) |
217 | } | 217 | } |
218 | } | 218 | } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 9d42b11c1..7d1d2a839 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html | |||
@@ -37,7 +37,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
37 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } | 37 | .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } |
38 | </style> | 38 | </style> |
39 | <pre><code><span class="comment documentation">/// ```</span> | 39 | <pre><code><span class="comment documentation">/// ```</span> |
40 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="punctuation injected">_</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="punctuation injected">;</span> | 40 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="punctuation injected">;</span> |
41 | <span class="comment documentation">/// ```</span> | 41 | <span class="comment documentation">/// ```</span> |
42 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> | 42 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> |
43 | <span class="field declaration">bar</span><span class="punctuation">:</span> <span class="builtin_type">bool</span><span class="punctuation">,</span> | 43 | <span class="field declaration">bar</span><span class="punctuation">:</span> <span class="builtin_type">bool</span><span class="punctuation">,</span> |
@@ -45,7 +45,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
45 | 45 | ||
46 | <span class="keyword">impl</span> <span class="struct">Foo</span> <span class="punctuation">{</span> | 46 | <span class="keyword">impl</span> <span class="struct">Foo</span> <span class="punctuation">{</span> |
47 | <span class="comment documentation">/// ```</span> | 47 | <span class="comment documentation">/// ```</span> |
48 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="punctuation injected">_</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"Call me</span> | 48 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Call me</span> |
49 | <span class="comment">// KILLER WHALE</span> | 49 | <span class="comment">// KILLER WHALE</span> |
50 | <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="punctuation injected">;</span> | 50 | <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="punctuation injected">;</span> |
51 | <span class="comment documentation">/// ```</span> | 51 | <span class="comment documentation">/// ```</span> |
@@ -56,8 +56,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
56 | <span class="comment documentation">/// # Examples</span> | 56 | <span class="comment documentation">/// # Examples</span> |
57 | <span class="comment documentation">///</span> | 57 | <span class="comment documentation">///</span> |
58 | <span class="comment documentation">/// ```</span> | 58 | <span class="comment documentation">/// ```</span> |
59 | <span class="comment documentation">/// #</span><span class="dummy injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="punctuation attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="punctuation attribute injected">)</span><span class="attribute attribute injected">]</span> | 59 | <span class="comment documentation">/// #</span><span class="none injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="punctuation attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="punctuation attribute injected">)</span><span class="attribute attribute injected">]</span> |
60 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="keyword injected">mut</span><span class="dummy injected"> </span><span class="variable declaration injected mutable">foo</span><span class="punctuation injected">:</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> | 60 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="keyword injected">mut</span><span class="none injected"> </span><span class="variable declaration injected mutable">foo</span><span class="punctuation injected">:</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> |
61 | <span class="comment documentation">/// ```</span> | 61 | <span class="comment documentation">/// ```</span> |
62 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration static associated">new</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="struct">Foo</span> <span class="punctuation">{</span> | 62 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration static associated">new</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="struct">Foo</span> <span class="punctuation">{</span> |
63 | <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">bar</span><span class="punctuation">:</span> <span class="bool_literal">true</span> <span class="punctuation">}</span> | 63 | <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">bar</span><span class="punctuation">:</span> <span class="bool_literal">true</span> <span class="punctuation">}</span> |
@@ -68,26 +68,26 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
68 | <span class="comment documentation">/// # Examples</span> | 68 | <span class="comment documentation">/// # Examples</span> |
69 | <span class="comment documentation">///</span> | 69 | <span class="comment documentation">///</span> |
70 | <span class="comment documentation">/// ```</span> | 70 | <span class="comment documentation">/// ```</span> |
71 | <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="dummy injected"> </span><span class="module injected">x</span><span class="operator injected">::</span><span class="module injected">y</span><span class="punctuation injected">;</span> | 71 | <span class="comment documentation">/// </span><span class="keyword injected">use</span><span class="none injected"> </span><span class="module injected">x</span><span class="operator injected">::</span><span class="module injected">y</span><span class="punctuation injected">;</span> |
72 | <span class="comment documentation">///</span> | 72 | <span class="comment documentation">///</span> |
73 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">foo</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> | 73 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> |
74 | <span class="comment documentation">///</span> | 74 | <span class="comment documentation">///</span> |
75 | <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span> | 75 | <span class="comment documentation">/// </span><span class="comment injected">// calls bar on foo</span> |
76 | <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="punctuation injected">(</span><span class="dummy injected">foo</span><span class="operator injected">.</span><span class="dummy injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> | 76 | <span class="comment documentation">/// </span><span class="macro injected">assert!</span><span class="punctuation injected">(</span><span class="none injected">foo</span><span class="operator injected">.</span><span class="none injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> |
77 | <span class="comment documentation">///</span> | 77 | <span class="comment documentation">///</span> |
78 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">bar</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="variable injected">foo</span><span class="operator injected">.</span><span class="field injected">bar</span><span class="dummy injected"> </span><span class="operator injected">||</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="constant injected">bar</span><span class="punctuation injected">;</span> | 78 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">bar</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="variable injected">foo</span><span class="operator injected">.</span><span class="field injected">bar</span><span class="none injected"> </span><span class="operator injected">||</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="constant injected">bar</span><span class="punctuation injected">;</span> |
79 | <span class="comment documentation">///</span> | 79 | <span class="comment documentation">///</span> |
80 | <span class="comment documentation">/// </span><span class="comment injected">/* multi-line</span> | 80 | <span class="comment documentation">/// </span><span class="comment injected">/* multi-line</span> |
81 | <span class="comment documentation">/// </span><span class="comment injected"> comment */</span> | 81 | <span class="comment documentation">/// </span><span class="comment injected"> comment */</span> |
82 | <span class="comment documentation">///</span> | 82 | <span class="comment documentation">///</span> |
83 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">multi_line_string</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="string_literal injected">"Foo</span> | 83 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">multi_line_string</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Foo</span> |
84 | <span class="comment documentation">/// </span><span class="string_literal injected"> bar</span> | 84 | <span class="comment documentation">/// </span><span class="string_literal injected"> bar</span> |
85 | <span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="punctuation injected">;</span> | 85 | <span class="comment documentation">/// </span><span class="string_literal injected"> "</span><span class="punctuation injected">;</span> |
86 | <span class="comment documentation">///</span> | 86 | <span class="comment documentation">///</span> |
87 | <span class="comment documentation">/// ```</span> | 87 | <span class="comment documentation">/// ```</span> |
88 | <span class="comment documentation">///</span> | 88 | <span class="comment documentation">///</span> |
89 | <span class="comment documentation">/// ```rust,no_run</span> | 89 | <span class="comment documentation">/// ```rust,no_run</span> |
90 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="dummy injected"> </span><span class="variable declaration injected">foobar</span><span class="dummy injected"> </span><span class="operator injected">=</span><span class="dummy injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="operator injected">.</span><span class="function injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> | 90 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="variable declaration injected">foobar</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="operator injected">.</span><span class="function injected">bar</span><span class="punctuation injected">(</span><span class="punctuation injected">)</span><span class="punctuation injected">;</span> |
91 | <span class="comment documentation">/// ```</span> | 91 | <span class="comment documentation">/// ```</span> |
92 | <span class="comment documentation">///</span> | 92 | <span class="comment documentation">///</span> |
93 | <span class="comment documentation">/// ```sh</span> | 93 | <span class="comment documentation">/// ```sh</span> |
diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html index a54d303b4..6703a84e5 100644 --- a/crates/ide/src/syntax_highlighting/test_data/injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/injection.html | |||
@@ -40,9 +40,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
40 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 40 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
41 | <span class="function">f</span><span class="punctuation">(</span><span class="string_literal">r"</span> | 41 | <span class="function">f</span><span class="punctuation">(</span><span class="string_literal">r"</span> |
42 | <span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | 42 | <span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> |
43 | <span class="function">foo</span><span class="punctuation">(</span>$0<span class="punctuation">{</span> | 43 | <span class="function">foo</span><span class="punctuation">(</span><span class="keyword">$0</span><span class="punctuation">{</span> |
44 | <span class="numeric_literal">92</span> | 44 | <span class="numeric_literal">92</span> |
45 | <span class="punctuation">}</span>$0<span class="punctuation">)</span> | 45 | <span class="punctuation">}</span><span class="keyword">$0</span><span class="punctuation">)</span> |
46 | <span class="punctuation">}</span><span class="string_literal">"</span><span class="punctuation">)</span><span class="punctuation">;</span> | 46 | <span class="punctuation">}</span><span class="string_literal">"</span><span class="punctuation">)</span><span class="punctuation">;</span> |
47 | <span class="punctuation">}</span> | 47 | <span class="punctuation">}</span> |
48 | </code></pre> \ No newline at end of file | 48 | </code></pre> \ No newline at end of file |