use lsp_types::{
CompletionOptions, HoverProviderCapability, SemanticTokenModifier as LspModifier,
SemanticTokenType as LspTokenType, SemanticTokensFullOptions, SemanticTokensLegend,
SemanticTokensOptions, SemanticTokensServerCapabilities, ServerCapabilities,
TextDocumentSyncCapability, TextDocumentSyncKind,
};
const COMPLETION_TRIGGER_CHARACTERS: [&str; 5] = ["@", ".", "$", "=", ":"];
pub fn server_capabilities() -> ServerCapabilities {
ServerCapabilities {
text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)),
completion_provider: Some(CompletionOptions {
trigger_characters: Some(
COMPLETION_TRIGGER_CHARACTERS
.iter()
.map(|c| c.to_string())
.collect(),
),
..Default::default()
}),
definition_provider: Some(lsp_types::OneOf::Left(true)),
hover_provider: Some(HoverProviderCapability::Simple(true)),
semantic_tokens_provider: Some(SemanticTokensServerCapabilities::SemanticTokensOptions(
SemanticTokensOptions {
work_done_progress_options: Default::default(),
legend: semantic_token_legend(),
range: Some(false),
full: Some(SemanticTokensFullOptions::Bool(true)),
},
)),
..Default::default()
}
}
fn semantic_token_legend() -> SemanticTokensLegend {
SemanticTokensLegend {
token_types: vec![
LspTokenType::KEYWORD, LspTokenType::NUMBER, LspTokenType::STRING, LspTokenType::COMMENT, LspTokenType::OPERATOR, LspTokenType::PROPERTY, LspTokenType::new("punctuation"), LspTokenType::MACRO, LspTokenType::DECORATOR, LspTokenType::new("sectionMarker"), LspTokenType::new("extensionMarker"), LspTokenType::new("extensionIdent"), ],
token_modifiers: vec![
LspModifier::DECLARATION, LspModifier::DEFINITION, LspModifier::new("sectionHeader"), ],
}
}