use std::sync::LazyLock;
use tower_lsp::lsp_types::{SemanticTokenModifier, SemanticTokenType, SemanticTokensLegend};
pub static SEMANTIC_TOKEN_LEGEND: LazyLock<SemanticTokensLegend> =
LazyLock::new(|| SemanticTokensLegend {
token_types: vec![
SemanticTokenType::NAMESPACE,
SemanticTokenType::TYPE,
SemanticTokenType::CLASS,
SemanticTokenType::ENUM,
SemanticTokenType::INTERFACE,
SemanticTokenType::STRUCT,
SemanticTokenType::TYPE_PARAMETER,
SemanticTokenType::PARAMETER,
SemanticTokenType::VARIABLE,
SemanticTokenType::PROPERTY,
SemanticTokenType::ENUM_MEMBER,
SemanticTokenType::EVENT,
SemanticTokenType::FUNCTION,
SemanticTokenType::METHOD,
SemanticTokenType::MACRO,
SemanticTokenType::KEYWORD,
SemanticTokenType::MODIFIER,
SemanticTokenType::COMMENT,
SemanticTokenType::STRING,
SemanticTokenType::NUMBER,
SemanticTokenType::REGEXP,
SemanticTokenType::OPERATOR,
],
token_modifiers: vec![
SemanticTokenModifier::DECLARATION,
SemanticTokenModifier::DEFINITION,
SemanticTokenModifier::READONLY,
SemanticTokenModifier::STATIC,
SemanticTokenModifier::DEPRECATED,
SemanticTokenModifier::ABSTRACT,
SemanticTokenModifier::ASYNC,
SemanticTokenModifier::MODIFICATION,
SemanticTokenModifier::DOCUMENTATION,
SemanticTokenModifier::DEFAULT_LIBRARY,
],
});
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RuchyTokenType {
Actor,
DataFrame,
Pipeline,
Pattern,
}
pub fn ruchy_token_to_lsp(token: RuchyTokenType) -> SemanticTokenType {
match token {
RuchyTokenType::Actor => SemanticTokenType::CLASS,
RuchyTokenType::DataFrame => SemanticTokenType::TYPE,
RuchyTokenType::Pipeline => SemanticTokenType::OPERATOR,
RuchyTokenType::Pattern => SemanticTokenType::ENUM_MEMBER,
}
}
#[cfg(test)]
mod property_tests_capabilities {
use proptest::prelude::*;
proptest! {
#[test]
fn test_ruchy_token_to_lsp_never_panics(input: String) {
let _input = if input.len() > 100 { &input[..100] } else { &input[..] };
let _ = std::panic::catch_unwind(|| {
});
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_semantic_token_legend_has_token_types() {
assert!(!SEMANTIC_TOKEN_LEGEND.token_types.is_empty());
assert!(SEMANTIC_TOKEN_LEGEND
.token_types
.contains(&SemanticTokenType::KEYWORD));
assert!(SEMANTIC_TOKEN_LEGEND
.token_types
.contains(&SemanticTokenType::FUNCTION));
}
#[test]
fn test_semantic_token_legend_has_modifiers() {
assert!(!SEMANTIC_TOKEN_LEGEND.token_modifiers.is_empty());
assert!(SEMANTIC_TOKEN_LEGEND
.token_modifiers
.contains(&SemanticTokenModifier::DECLARATION));
}
#[test]
fn test_ruchy_token_to_lsp_actor() {
let result = ruchy_token_to_lsp(RuchyTokenType::Actor);
assert_eq!(result, SemanticTokenType::CLASS);
}
#[test]
fn test_ruchy_token_to_lsp_dataframe() {
let result = ruchy_token_to_lsp(RuchyTokenType::DataFrame);
assert_eq!(result, SemanticTokenType::TYPE);
}
#[test]
fn test_ruchy_token_to_lsp_pipeline() {
let result = ruchy_token_to_lsp(RuchyTokenType::Pipeline);
assert_eq!(result, SemanticTokenType::OPERATOR);
}
#[test]
fn test_ruchy_token_to_lsp_pattern() {
let result = ruchy_token_to_lsp(RuchyTokenType::Pattern);
assert_eq!(result, SemanticTokenType::ENUM_MEMBER);
}
#[test]
fn test_ruchy_token_type_eq() {
assert_eq!(RuchyTokenType::Actor, RuchyTokenType::Actor);
assert_ne!(RuchyTokenType::Actor, RuchyTokenType::DataFrame);
}
#[test]
fn test_ruchy_token_type_clone() {
let token = RuchyTokenType::Pipeline;
let cloned = token;
assert_eq!(cloned, RuchyTokenType::Pipeline);
}
}