Skip to main content

eure_ls/
capabilities.rs

1//! Server capabilities definition.
2
3use lsp_types::{
4    SemanticTokenModifier as LspModifier, SemanticTokenType as LspTokenType,
5    SemanticTokensFullOptions, SemanticTokensLegend, SemanticTokensOptions,
6    SemanticTokensServerCapabilities, ServerCapabilities, TextDocumentSyncCapability,
7    TextDocumentSyncKind,
8};
9
10/// Build the server capabilities to advertise to the client.
11pub fn server_capabilities() -> ServerCapabilities {
12    ServerCapabilities {
13        text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)),
14        semantic_tokens_provider: Some(SemanticTokensServerCapabilities::SemanticTokensOptions(
15            SemanticTokensOptions {
16                work_done_progress_options: Default::default(),
17                legend: semantic_token_legend(),
18                range: Some(false),
19                full: Some(SemanticTokensFullOptions::Bool(true)),
20            },
21        )),
22        ..Default::default()
23    }
24}
25
26/// Build the semantic token legend.
27///
28/// The legend defines the mapping from token type/modifier indices to names.
29/// This must match the order defined in `SemanticTokenType` and `SemanticTokenModifier`.
30fn semantic_token_legend() -> SemanticTokensLegend {
31    SemanticTokensLegend {
32        token_types: vec![
33            LspTokenType::KEYWORD,                // Keyword = 0
34            LspTokenType::NUMBER,                 // Number = 1
35            LspTokenType::STRING,                 // String = 2
36            LspTokenType::COMMENT,                // Comment = 3
37            LspTokenType::OPERATOR,               // Operator = 4
38            LspTokenType::PROPERTY,               // Property = 5
39            LspTokenType::new("punctuation"),     // Punctuation = 6
40            LspTokenType::MACRO,                  // Macro = 7
41            LspTokenType::DECORATOR,              // Decorator = 8
42            LspTokenType::new("sectionMarker"),   // SectionMarker = 9
43            LspTokenType::new("extensionMarker"), // ExtensionMarker = 10
44            LspTokenType::new("extensionIdent"),  // ExtensionIdent = 11
45        ],
46        token_modifiers: vec![
47            LspModifier::DECLARATION,          // Declaration = 0
48            LspModifier::DEFINITION,           // Definition = 1
49            LspModifier::new("sectionHeader"), // SectionHeader = 2
50        ],
51    }
52}