feat: enable LSP semantic token highlighting by default

This commit is contained in:
2026-10-09 22:17:30 +02:00
parent 548711980c
commit d418d670ee
13 changed files with 1714 additions and 84 deletions
+61 -1
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, sync::Arc};
use serde::{Deserialize, Serialize};
@@ -52,6 +52,59 @@ pub struct Diagnostic {
pub message: String,
}
/// Standard LSP semantic token categories, independent of frontend colors.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SemanticTokenKind {
Namespace,
Type,
Class,
Enum,
Interface,
Struct,
TypeParameter,
Parameter,
Variable,
Property,
EnumMember,
Event,
Function,
Method,
Macro,
Keyword,
Modifier,
Comment,
String,
Number,
Regexp,
Operator,
Decorator,
}
/// Canonical modifier bits; server legend bit positions are translated by LSP.
#[repr(u16)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SemanticTokenModifier {
Declaration = 1,
Definition = 1 << 1,
Readonly = 1 << 2,
Static = 1 << 3,
Deprecated = 1 << 4,
Abstract = 1 << 5,
Async = 1 << 6,
Modification = 1 << 7,
Documentation = 1 << 8,
DefaultLibrary = 1 << 9,
}
/// A single-line foreground annotation using whole extended-grapheme positions.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SemanticToken {
pub start: TextPosition,
pub end: TextPosition,
pub kind: SemanticTokenKind,
pub modifiers: u16,
}
#[derive(Debug, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
pub enum UpdateEffect {
@@ -60,6 +113,13 @@ pub enum UpdateEffect {
revision: u64,
items: Vec<Diagnostic>,
},
#[serde(skip_deserializing)]
SemanticTokens {
buffer_id: usize,
revision: u64,
/// None clears the overlay. Immutable slices are shared without copying.
tokens: Option<Arc<[SemanticToken]>>,
},
Navigate {
buffer_id: usize,
revision: u64,