Skip to content

Commit 77362c7

Browse files
bors[bot]Veykril
andauthored
Merge #6238
6238: Split punctuation semantic highlighting up into more tags r=matklad a=Veykril Open question would be the name of the delimiter modifiers. I chose them this was as I see them this way but from what I remember people tend to mix the names however they like. So maybe using `delimSquare`, `delimCurly`, `delimRound` would be better. That would also go well with `angle` becoming `delimAngle`? Closes #6152 Co-authored-by: Lukas Wirth <[email protected]>
2 parents dcbb77c + 78fe613 commit 77362c7

14 files changed

+368
-307
lines changed

crates/ide/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use crate::{
7676
references::{rename::RenameError, Declaration, ReferenceSearchResult},
7777
runnables::{Runnable, RunnableKind, TestId},
7878
syntax_highlighting::{
79-
tags::{Highlight, HlMod, HlMods, HlTag},
79+
tags::{Highlight, HlMod, HlMods, HlPunct, HlTag},
8080
HlRange,
8181
},
8282
};

crates/ide/src/syntax_highlighting/highlight.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syntax::{
1212
SyntaxNode, SyntaxToken, T,
1313
};
1414

15-
use crate::{Highlight, HlMod, HlTag, SymbolKind};
15+
use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind};
1616

1717
pub(super) fn element(
1818
sema: &Semantics<RootDatabase>,
@@ -173,7 +173,7 @@ pub(super) fn element(
173173
} else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() {
174174
HlTag::Operator.into()
175175
} else {
176-
HlTag::Punctuation.into()
176+
HlTag::Punctuation(HlPunct::Other).into()
177177
}
178178
}
179179
T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
@@ -196,7 +196,18 @@ pub(super) fn element(
196196
_ if element.parent().and_then(ast::RangePat::cast).is_some() => HlTag::Operator.into(),
197197
_ if element.parent().and_then(ast::RestPat::cast).is_some() => HlTag::Operator.into(),
198198
_ if element.parent().and_then(ast::Attr::cast).is_some() => HlTag::Attribute.into(),
199-
_ => HlTag::Punctuation.into(),
199+
kind => HlTag::Punctuation(match kind {
200+
T!['['] | T![']'] => HlPunct::Bracket,
201+
T!['{'] | T!['}'] => HlPunct::Brace,
202+
T!['('] | T![')'] => HlPunct::Parenthesis,
203+
T![<] | T![>] => HlPunct::Angle,
204+
T![,] => HlPunct::Comma,
205+
T![:] => HlPunct::Colon,
206+
T![;] => HlPunct::Semi,
207+
T![.] => HlPunct::Dot,
208+
_ => HlPunct::Other,
209+
})
210+
.into(),
200211
},
201212

202213
k if k.is_keyword() => {

crates/ide/src/syntax_highlighting/tags.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum HlTag {
2929
EscapeSequence,
3030
FormatSpecifier,
3131
Keyword,
32-
Punctuation,
32+
Punctuation(HlPunct),
3333
Operator,
3434
UnresolvedReference,
3535

@@ -61,6 +61,28 @@ pub enum HlMod {
6161
Unsafe,
6262
}
6363

64+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
65+
pub enum HlPunct {
66+
/// []
67+
Bracket,
68+
/// {}
69+
Brace,
70+
/// ()
71+
Parenthesis,
72+
/// <>
73+
Angle,
74+
/// ,
75+
Comma,
76+
/// .
77+
Dot,
78+
/// :
79+
Colon,
80+
/// ;
81+
Semi,
82+
///
83+
Other,
84+
}
85+
6486
impl HlTag {
6587
fn as_str(self) -> &'static str {
6688
match self {
@@ -95,7 +117,17 @@ impl HlTag {
95117
HlTag::EscapeSequence => "escape_sequence",
96118
HlTag::FormatSpecifier => "format_specifier",
97119
HlTag::Keyword => "keyword",
98-
HlTag::Punctuation => "punctuation",
120+
HlTag::Punctuation(punct) => match punct {
121+
HlPunct::Bracket => "bracket",
122+
HlPunct::Brace => "brace",
123+
HlPunct::Parenthesis => "parentheses",
124+
HlPunct::Angle => "angle",
125+
HlPunct::Comma => "comma",
126+
HlPunct::Dot => "dot",
127+
HlPunct::Colon => "colon",
128+
HlPunct::Semi => "semicolon",
129+
HlPunct::Other => "punctuation",
130+
},
99131
HlTag::NumericLiteral => "numeric_literal",
100132
HlTag::Operator => "operator",
101133
HlTag::StringLiteral => "string_literal",

crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636

3737
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
3838
</style>
39-
<pre><code><span class="keyword">fn</span> <span class="function declaration">not_static</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
39+
<pre><code><span class="keyword">fn</span> <span class="function declaration">not_static</span><span class="parentheses">(</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
4040

41-
<span class="keyword">struct</span> <span class="struct declaration">foo</span> <span class="punctuation">{</span><span class="punctuation">}</span>
41+
<span class="keyword">struct</span> <span class="struct declaration">foo</span> <span class="brace">{</span><span class="brace">}</span>
4242

43-
<span class="keyword">impl</span> <span class="struct">foo</span> <span class="punctuation">{</span>
44-
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
45-
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
46-
<span class="punctuation">}</span>
43+
<span class="keyword">impl</span> <span class="struct">foo</span> <span class="brace">{</span>
44+
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="parentheses">(</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
45+
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="parentheses">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
46+
<span class="brace">}</span>
4747

48-
<span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="punctuation">{</span>
49-
<span class="keyword">fn</span> <span class="function declaration static associated">t_is_static</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
50-
<span class="keyword">fn</span> <span class="function declaration associated">t_is_not_static</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
51-
<span class="punctuation">}</span>
48+
<span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span>
49+
<span class="keyword">fn</span> <span class="function declaration static associated">t_is_static</span><span class="parentheses">(</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
50+
<span class="keyword">fn</span> <span class="function declaration associated">t_is_not_static</span><span class="parentheses">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
51+
<span class="brace">}</span>
5252

53-
<span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="punctuation">{</span>
54-
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
55-
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="punctuation">{</span><span class="punctuation">}</span>
56-
<span class="punctuation">}</span>
53+
<span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span>
54+
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="parentheses">(</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
55+
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="parentheses">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="parentheses">)</span> <span class="brace">{</span><span class="brace">}</span>
56+
<span class="brace">}</span>
5757
</code></pre>

0 commit comments

Comments
 (0)