use std::{path::PathBuf, sync::Arc}; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize)] pub struct DocumentSnapshot { pub id: usize, pub revision: u64, pub path: Option, pub root: String, pub text: String, } #[derive(Clone, Copy, Debug, Serialize)] #[serde(rename_all = "snake_case")] pub enum DocumentEventKind { Open, Change, Save, Close, } #[derive(Clone, Debug, Serialize)] pub struct DocumentEvent { pub event: DocumentEventKind, pub document: DocumentSnapshot, } #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum DiagnosticSeverity { Error, Warning, Information, Hint, } /// Zero-based extended-grapheme positions, independent of any server encoding. #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd)] #[serde(deny_unknown_fields)] pub struct TextPosition { pub row: usize, pub column: usize, } #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] #[serde(deny_unknown_fields)] pub struct Diagnostic { pub start: TextPosition, pub end: TextPosition, pub severity: DiagnosticSeverity, 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, } /// A completion replacement in zero-based, end-exclusive grapheme coordinates. #[derive(Clone, Debug, Eq, PartialEq)] pub struct CompletionEdit { pub start: TextPosition, pub end: TextPosition, pub text: String, } /// Protocol-independent completion text and its atomic document edits. #[derive(Clone, Debug, Eq, PartialEq)] pub struct CompletionItem { pub label: String, pub detail: Option, /// Index of the primary replacement; other edits never determine caret placement. pub primary_edit: usize, pub edits: Vec, } #[derive(Debug, Deserialize)] #[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)] pub enum UpdateEffect { Diagnostics { buffer_id: usize, revision: u64, items: Vec, }, #[serde(skip_deserializing)] SemanticTokens { buffer_id: usize, revision: u64, /// None clears the overlay. Immutable slices are shared without copying. tokens: Option>, }, Navigate { buffer_id: usize, revision: u64, path: PathBuf, row: usize, column: usize, }, Hover { buffer_id: usize, revision: u64, text: String, }, #[serde(skip_deserializing)] Completion { buffer_id: usize, revision: u64, items: Vec, }, Message { text: String, }, } #[derive(Debug)] pub struct PluginUpdate { pub request_id: Option, pub effects: Vec, } #[derive(Debug)] pub enum PluginEvent { Response { id: u64, effects: Vec, }, Update(PluginUpdate), }