Skip to main content

eure_ls/
capabilities.rs

1//! Server capabilities definition.
2
3use lsp_types::{
4    CompletionOptions, HoverProviderCapability, SemanticTokenModifier as LspModifier,
5    SemanticTokenType as LspTokenType, SemanticTokensFullOptions, SemanticTokensLegend,
6    SemanticTokensOptions, SemanticTokensServerCapabilities, ServerCapabilities,
7    TextDocumentSyncCapability, TextDocumentSyncKind,
8};
9
10/// Characters that start a new completable position in Eure syntax:
11/// section marker, key separator, extension marker, and the two binding
12/// operators.
13const COMPLETION_TRIGGER_CHARACTERS: [&str; 5] = ["@", ".", "$", "=", ":"];
14
15/// Build the server capabilities to advertise to the client.
16pub fn server_capabilities() -> ServerCapabilities {
17    ServerCapabilities {
18        text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)),
19        completion_provider: Some(CompletionOptions {
20            trigger_characters: Some(
21                COMPLETION_TRIGGER_CHARACTERS
22                    .iter()
23                    .map(|c| c.to_string())
24                    .collect(),
25            ),
26            ..Default::default()
27        }),
28        definition_provider: Some(lsp_types::OneOf::Left(true)),
29        hover_provider: Some(HoverProviderCapability::Simple(true)),
30        semantic_tokens_provider: Some(SemanticTokensServerCapabilities::SemanticTokensOptions(
31            SemanticTokensOptions {
32                work_done_progress_options: Default::default(),
33                legend: semantic_token_legend(),
34                range: Some(false),
35                full: Some(SemanticTokensFullOptions::Bool(true)),
36            },
37        )),
38        ..Default::default()
39    }
40}
41
42/// Build the semantic token legend.
43///
44/// The legend defines the mapping from token type/modifier indices to names.
45/// This must match the order defined in `SemanticTokenType` and `SemanticTokenModifier`.
46fn semantic_token_legend() -> SemanticTokensLegend {
47    SemanticTokensLegend {
48        token_types: vec![
49            LspTokenType::KEYWORD,                // Keyword = 0
50            LspTokenType::NUMBER,                 // Number = 1
51            LspTokenType::STRING,                 // String = 2
52            LspTokenType::COMMENT,                // Comment = 3
53            LspTokenType::OPERATOR,               // Operator = 4
54            LspTokenType::PROPERTY,               // Property = 5
55            LspTokenType::new("punctuation"),     // Punctuation = 6
56            LspTokenType::MACRO,                  // Macro = 7
57            LspTokenType::DECORATOR,              // Decorator = 8
58            LspTokenType::new("sectionMarker"),   // SectionMarker = 9
59            LspTokenType::new("extensionMarker"), // ExtensionMarker = 10
60            LspTokenType::new("extensionIdent"),  // ExtensionIdent = 11
61        ],
62        token_modifiers: vec![
63            LspModifier::DECLARATION,          // Declaration = 0
64            LspModifier::DEFINITION,           // Definition = 1
65            LspModifier::new("sectionHeader"), // SectionHeader = 2
66        ],
67    }
68}