4193: Make it impossible to forget to add a semantic token type / modifier r=kjeremy a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-04-28 20:05:08 +00:00 committed by GitHub
commit db441de0a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,64 +4,69 @@ use std::ops;
use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens}; use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens};
pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute"); macro_rules! define_semantic_token_types {
pub(crate) const BUILTIN_TYPE: SemanticTokenType = SemanticTokenType::new("builtinType"); ($(($ident:ident, $string:literal)),*$(,)?) => {
pub(crate) const ENUM_MEMBER: SemanticTokenType = SemanticTokenType::new("enumMember"); $(pub(crate) const $ident: SemanticTokenType = SemanticTokenType::new($string);)*
pub(crate) const LIFETIME: SemanticTokenType = SemanticTokenType::new("lifetime");
pub(crate) const TYPE_ALIAS: SemanticTokenType = SemanticTokenType::new("typeAlias");
pub(crate) const UNION: SemanticTokenType = SemanticTokenType::new("union");
pub(crate) const UNRESOLVED_REFERENCE: SemanticTokenType =
SemanticTokenType::new("unresolvedReference");
pub(crate) const FORMAT_SPECIFIER: SemanticTokenType = SemanticTokenType::new("formatSpecifier");
pub(crate) const CONSTANT: SemanticTokenModifier = SemanticTokenModifier::new("constant"); pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
pub(crate) const CONTROL_FLOW: SemanticTokenModifier = SemanticTokenModifier::new("controlFlow"); SemanticTokenType::COMMENT,
pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable"); SemanticTokenType::KEYWORD,
pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe"); SemanticTokenType::STRING,
SemanticTokenType::NUMBER,
SemanticTokenType::REGEXP,
SemanticTokenType::OPERATOR,
SemanticTokenType::NAMESPACE,
SemanticTokenType::TYPE,
SemanticTokenType::STRUCT,
SemanticTokenType::CLASS,
SemanticTokenType::INTERFACE,
SemanticTokenType::ENUM,
SemanticTokenType::TYPE_PARAMETER,
SemanticTokenType::FUNCTION,
SemanticTokenType::MEMBER,
SemanticTokenType::PROPERTY,
SemanticTokenType::MACRO,
SemanticTokenType::VARIABLE,
SemanticTokenType::PARAMETER,
SemanticTokenType::LABEL,
$($ident),*
];
};
}
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[ define_semantic_token_types![
SemanticTokenType::COMMENT, (ATTRIBUTE, "attribute"),
SemanticTokenType::KEYWORD, (BUILTIN_TYPE, "builtinType"),
SemanticTokenType::STRING, (ENUM_MEMBER, "enumMember"),
SemanticTokenType::NUMBER, (LIFETIME, "lifetime"),
SemanticTokenType::REGEXP, (TYPE_ALIAS, "typeAlias"),
SemanticTokenType::OPERATOR, (UNION, "union"),
SemanticTokenType::NAMESPACE, (UNRESOLVED_REFERENCE, "unresolvedReference"),
SemanticTokenType::TYPE, (FORMAT_SPECIFIER, "formatSpecifier"),
SemanticTokenType::STRUCT,
SemanticTokenType::CLASS,
SemanticTokenType::INTERFACE,
SemanticTokenType::ENUM,
SemanticTokenType::TYPE_PARAMETER,
SemanticTokenType::FUNCTION,
SemanticTokenType::MEMBER,
SemanticTokenType::PROPERTY,
SemanticTokenType::MACRO,
SemanticTokenType::VARIABLE,
SemanticTokenType::PARAMETER,
SemanticTokenType::LABEL,
ATTRIBUTE,
BUILTIN_TYPE,
ENUM_MEMBER,
LIFETIME,
TYPE_ALIAS,
UNION,
UNRESOLVED_REFERENCE,
FORMAT_SPECIFIER,
]; ];
pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[ macro_rules! define_semantic_token_modifiers {
SemanticTokenModifier::DOCUMENTATION, ($(($ident:ident, $string:literal)),*$(,)?) => {
SemanticTokenModifier::DECLARATION, $(pub(crate) const $ident: SemanticTokenModifier = SemanticTokenModifier::new($string);)*
SemanticTokenModifier::DEFINITION,
SemanticTokenModifier::STATIC, pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
SemanticTokenModifier::ABSTRACT, SemanticTokenModifier::DOCUMENTATION,
SemanticTokenModifier::DEPRECATED, SemanticTokenModifier::DECLARATION,
SemanticTokenModifier::READONLY, SemanticTokenModifier::DEFINITION,
CONSTANT, SemanticTokenModifier::STATIC,
MUTABLE, SemanticTokenModifier::ABSTRACT,
UNSAFE, SemanticTokenModifier::DEPRECATED,
CONTROL_FLOW, SemanticTokenModifier::READONLY,
$($ident),*
];
};
}
define_semantic_token_modifiers![
(CONSTANT, "constant"),
(CONTROL_FLOW, "controlFlow"),
(MUTABLE, "mutable"),
(UNSAFE, "unsafe"),
]; ];
#[derive(Default)] #[derive(Default)]