diff options
author | Aleksey Kladov <[email protected]> | 2020-12-18 20:00:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-12-18 20:04:26 +0000 |
commit | c45221907adde640208a9e52636f4845d4654994 (patch) | |
tree | 7f64801f5d8fb520196b8a69f74078d408579a62 /crates/rust-analyzer/src/to_proto.rs | |
parent | 25185c1418022868e2f7ec1599e32a34d63e8314 (diff) |
Deduplicate highlight tags and symbol kinds
Curiously, LSP uses different enums for those, and unsurprising and
annoyingly, there are things which exist in one but not in the other.
Let's not repeat the mistake and unify the two things
Diffstat (limited to 'crates/rust-analyzer/src/to_proto.rs')
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 6b2302803..229df47dc 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -43,9 +43,10 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind { | |||
43 | SymbolKind::Static => lsp_types::SymbolKind::Constant, | 43 | SymbolKind::Static => lsp_types::SymbolKind::Constant, |
44 | SymbolKind::Const => lsp_types::SymbolKind::Constant, | 44 | SymbolKind::Const => lsp_types::SymbolKind::Constant, |
45 | SymbolKind::Impl => lsp_types::SymbolKind::Object, | 45 | SymbolKind::Impl => lsp_types::SymbolKind::Object, |
46 | SymbolKind::Local | SymbolKind::SelfParam | SymbolKind::LifetimeParam => { | 46 | SymbolKind::Local |
47 | lsp_types::SymbolKind::Variable | 47 | | SymbolKind::SelfParam |
48 | } | 48 | | SymbolKind::LifetimeParam |
49 | | SymbolKind::ValueParam => lsp_types::SymbolKind::Variable, | ||
49 | SymbolKind::Union => lsp_types::SymbolKind::Struct, | 50 | SymbolKind::Union => lsp_types::SymbolKind::Struct, |
50 | } | 51 | } |
51 | } | 52 | } |
@@ -371,34 +372,36 @@ fn semantic_token_type_and_modifiers( | |||
371 | ) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) { | 372 | ) -> (lsp_types::SemanticTokenType, semantic_tokens::ModifierSet) { |
372 | let mut mods = semantic_tokens::ModifierSet::default(); | 373 | let mut mods = semantic_tokens::ModifierSet::default(); |
373 | let type_ = match highlight.tag { | 374 | let type_ = match highlight.tag { |
374 | HighlightTag::Struct => lsp_types::SemanticTokenType::STRUCT, | 375 | HighlightTag::Symbol(symbol) => match symbol { |
375 | HighlightTag::Enum => lsp_types::SemanticTokenType::ENUM, | 376 | SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE, |
376 | HighlightTag::Union => semantic_tokens::UNION, | 377 | SymbolKind::Impl => lsp_types::SemanticTokenType::TYPE, |
377 | HighlightTag::TypeAlias => semantic_tokens::TYPE_ALIAS, | 378 | SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY, |
378 | HighlightTag::Trait => lsp_types::SemanticTokenType::INTERFACE, | 379 | SymbolKind::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER, |
380 | SymbolKind::LifetimeParam => semantic_tokens::LIFETIME, | ||
381 | SymbolKind::ValueParam => lsp_types::SemanticTokenType::PARAMETER, | ||
382 | SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD, | ||
383 | SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE, | ||
384 | SymbolKind::Function => lsp_types::SemanticTokenType::FUNCTION, | ||
385 | SymbolKind::Const => { | ||
386 | mods |= semantic_tokens::CONSTANT; | ||
387 | mods |= lsp_types::SemanticTokenModifier::STATIC; | ||
388 | lsp_types::SemanticTokenType::VARIABLE | ||
389 | } | ||
390 | SymbolKind::Static => { | ||
391 | mods |= lsp_types::SemanticTokenModifier::STATIC; | ||
392 | lsp_types::SemanticTokenType::VARIABLE | ||
393 | } | ||
394 | SymbolKind::Struct => lsp_types::SemanticTokenType::STRUCT, | ||
395 | SymbolKind::Enum => lsp_types::SemanticTokenType::ENUM, | ||
396 | SymbolKind::Variant => lsp_types::SemanticTokenType::ENUM_MEMBER, | ||
397 | SymbolKind::Union => semantic_tokens::UNION, | ||
398 | SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS, | ||
399 | SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE, | ||
400 | SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO, | ||
401 | }, | ||
379 | HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, | 402 | HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE, |
380 | HighlightTag::SelfKeyword => semantic_tokens::SELF_KEYWORD, | ||
381 | HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE, | ||
382 | HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY, | ||
383 | HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION, | ||
384 | HighlightTag::Generic => semantic_tokens::GENERIC, | 403 | HighlightTag::Generic => semantic_tokens::GENERIC, |
385 | HighlightTag::Module => lsp_types::SemanticTokenType::NAMESPACE, | ||
386 | HighlightTag::Method => lsp_types::SemanticTokenType::METHOD, | 404 | HighlightTag::Method => lsp_types::SemanticTokenType::METHOD, |
387 | HighlightTag::Constant => { | ||
388 | mods |= semantic_tokens::CONSTANT; | ||
389 | mods |= lsp_types::SemanticTokenModifier::STATIC; | ||
390 | lsp_types::SemanticTokenType::VARIABLE | ||
391 | } | ||
392 | HighlightTag::Static => { | ||
393 | mods |= lsp_types::SemanticTokenModifier::STATIC; | ||
394 | lsp_types::SemanticTokenType::VARIABLE | ||
395 | } | ||
396 | HighlightTag::EnumVariant => lsp_types::SemanticTokenType::ENUM_MEMBER, | ||
397 | HighlightTag::Macro => lsp_types::SemanticTokenType::MACRO, | ||
398 | HighlightTag::ValueParam => lsp_types::SemanticTokenType::PARAMETER, | ||
399 | HighlightTag::Local => lsp_types::SemanticTokenType::VARIABLE, | ||
400 | HighlightTag::TypeParam => lsp_types::SemanticTokenType::TYPE_PARAMETER, | ||
401 | HighlightTag::Lifetime => semantic_tokens::LIFETIME, | ||
402 | HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => { | 405 | HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => { |
403 | lsp_types::SemanticTokenType::NUMBER | 406 | lsp_types::SemanticTokenType::NUMBER |
404 | } | 407 | } |