Skip to content

Commit db441de

Browse files
bors[bot]matklad
andauthored
Merge #4193
4193: Make it impossible to forget to add a semantic token type / modifier r=kjeremy a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 2096db9 + 890938a commit db441de

File tree

1 file changed

+61
-56
lines changed

1 file changed

+61
-56
lines changed

crates/rust-analyzer/src/semantic_tokens.rs

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,69 @@ use std::ops;
44

55
use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens};
66

7-
pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute");
8-
pub(crate) const BUILTIN_TYPE: SemanticTokenType = SemanticTokenType::new("builtinType");
9-
pub(crate) const ENUM_MEMBER: SemanticTokenType = SemanticTokenType::new("enumMember");
10-
pub(crate) const LIFETIME: SemanticTokenType = SemanticTokenType::new("lifetime");
11-
pub(crate) const TYPE_ALIAS: SemanticTokenType = SemanticTokenType::new("typeAlias");
12-
pub(crate) const UNION: SemanticTokenType = SemanticTokenType::new("union");
13-
pub(crate) const UNRESOLVED_REFERENCE: SemanticTokenType =
14-
SemanticTokenType::new("unresolvedReference");
15-
pub(crate) const FORMAT_SPECIFIER: SemanticTokenType = SemanticTokenType::new("formatSpecifier");
16-
17-
pub(crate) const CONSTANT: SemanticTokenModifier = SemanticTokenModifier::new("constant");
18-
pub(crate) const CONTROL_FLOW: SemanticTokenModifier = SemanticTokenModifier::new("controlFlow");
19-
pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable");
20-
pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe");
21-
22-
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
23-
SemanticTokenType::COMMENT,
24-
SemanticTokenType::KEYWORD,
25-
SemanticTokenType::STRING,
26-
SemanticTokenType::NUMBER,
27-
SemanticTokenType::REGEXP,
28-
SemanticTokenType::OPERATOR,
29-
SemanticTokenType::NAMESPACE,
30-
SemanticTokenType::TYPE,
31-
SemanticTokenType::STRUCT,
32-
SemanticTokenType::CLASS,
33-
SemanticTokenType::INTERFACE,
34-
SemanticTokenType::ENUM,
35-
SemanticTokenType::TYPE_PARAMETER,
36-
SemanticTokenType::FUNCTION,
37-
SemanticTokenType::MEMBER,
38-
SemanticTokenType::PROPERTY,
39-
SemanticTokenType::MACRO,
40-
SemanticTokenType::VARIABLE,
41-
SemanticTokenType::PARAMETER,
42-
SemanticTokenType::LABEL,
43-
ATTRIBUTE,
44-
BUILTIN_TYPE,
45-
ENUM_MEMBER,
46-
LIFETIME,
47-
TYPE_ALIAS,
48-
UNION,
49-
UNRESOLVED_REFERENCE,
50-
FORMAT_SPECIFIER,
7+
macro_rules! define_semantic_token_types {
8+
($(($ident:ident, $string:literal)),*$(,)?) => {
9+
$(pub(crate) const $ident: SemanticTokenType = SemanticTokenType::new($string);)*
10+
11+
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
12+
SemanticTokenType::COMMENT,
13+
SemanticTokenType::KEYWORD,
14+
SemanticTokenType::STRING,
15+
SemanticTokenType::NUMBER,
16+
SemanticTokenType::REGEXP,
17+
SemanticTokenType::OPERATOR,
18+
SemanticTokenType::NAMESPACE,
19+
SemanticTokenType::TYPE,
20+
SemanticTokenType::STRUCT,
21+
SemanticTokenType::CLASS,
22+
SemanticTokenType::INTERFACE,
23+
SemanticTokenType::ENUM,
24+
SemanticTokenType::TYPE_PARAMETER,
25+
SemanticTokenType::FUNCTION,
26+
SemanticTokenType::MEMBER,
27+
SemanticTokenType::PROPERTY,
28+
SemanticTokenType::MACRO,
29+
SemanticTokenType::VARIABLE,
30+
SemanticTokenType::PARAMETER,
31+
SemanticTokenType::LABEL,
32+
$($ident),*
33+
];
34+
};
35+
}
36+
37+
define_semantic_token_types![
38+
(ATTRIBUTE, "attribute"),
39+
(BUILTIN_TYPE, "builtinType"),
40+
(ENUM_MEMBER, "enumMember"),
41+
(LIFETIME, "lifetime"),
42+
(TYPE_ALIAS, "typeAlias"),
43+
(UNION, "union"),
44+
(UNRESOLVED_REFERENCE, "unresolvedReference"),
45+
(FORMAT_SPECIFIER, "formatSpecifier"),
5146
];
5247

53-
pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
54-
SemanticTokenModifier::DOCUMENTATION,
55-
SemanticTokenModifier::DECLARATION,
56-
SemanticTokenModifier::DEFINITION,
57-
SemanticTokenModifier::STATIC,
58-
SemanticTokenModifier::ABSTRACT,
59-
SemanticTokenModifier::DEPRECATED,
60-
SemanticTokenModifier::READONLY,
61-
CONSTANT,
62-
MUTABLE,
63-
UNSAFE,
64-
CONTROL_FLOW,
48+
macro_rules! define_semantic_token_modifiers {
49+
($(($ident:ident, $string:literal)),*$(,)?) => {
50+
$(pub(crate) const $ident: SemanticTokenModifier = SemanticTokenModifier::new($string);)*
51+
52+
pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
53+
SemanticTokenModifier::DOCUMENTATION,
54+
SemanticTokenModifier::DECLARATION,
55+
SemanticTokenModifier::DEFINITION,
56+
SemanticTokenModifier::STATIC,
57+
SemanticTokenModifier::ABSTRACT,
58+
SemanticTokenModifier::DEPRECATED,
59+
SemanticTokenModifier::READONLY,
60+
$($ident),*
61+
];
62+
};
63+
}
64+
65+
define_semantic_token_modifiers![
66+
(CONSTANT, "constant"),
67+
(CONTROL_FLOW, "controlFlow"),
68+
(MUTABLE, "mutable"),
69+
(UNSAFE, "unsafe"),
6570
];
6671

6772
#[derive(Default)]

0 commit comments

Comments
 (0)