215 lines
5.2 KiB
Rust
215 lines
5.2 KiB
Rust
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<String>,
|
|
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,
|
|
}
|
|
|
|
/// Expanded snippet tabstops, in byte offsets relative to the primary edit text.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct CompletionSnippet {
|
|
/// Positive tabstops in ascending order, followed by the final zero tabstop.
|
|
pub tabstops: Vec<SnippetTabstop>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct SnippetTabstop {
|
|
pub index: u32,
|
|
/// Repeated occurrences of the same tabstop are edited together.
|
|
pub ranges: Vec<std::ops::Range<usize>>,
|
|
/// Enclosing numbered stops per occurrence, outermost first; parallel to ranges.
|
|
pub ancestors: Vec<Vec<u32>>,
|
|
}
|
|
|
|
/// Protocol-independent completion text and its atomic document edits.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct CompletionItem {
|
|
pub label: String,
|
|
pub detail: Option<String>,
|
|
/// Index of the primary replacement; other edits never determine caret placement.
|
|
pub primary_edit: usize,
|
|
pub edits: Vec<CompletionEdit>,
|
|
pub snippet: Option<CompletionSnippet>,
|
|
}
|
|
|
|
/// Native LSP range; each coordinate is (zero-based row, UTF-16 column).
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct Utf16Range {
|
|
pub start: (usize, usize),
|
|
pub end: (usize, usize),
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
|
|
pub enum UpdateEffect {
|
|
Diagnostics {
|
|
buffer_id: usize,
|
|
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,
|
|
path: PathBuf,
|
|
row: usize,
|
|
column: usize,
|
|
},
|
|
/// Native LSP targets retain UTF-16 coordinates until their source text is resolved.
|
|
#[serde(skip_deserializing)]
|
|
NavigateUtf16 {
|
|
buffer_id: usize,
|
|
revision: u64,
|
|
path: PathBuf,
|
|
range: Utf16Range,
|
|
target_range: Option<Utf16Range>,
|
|
},
|
|
Hover {
|
|
buffer_id: usize,
|
|
revision: u64,
|
|
text: String,
|
|
},
|
|
#[serde(skip_deserializing)]
|
|
Completion {
|
|
buffer_id: usize,
|
|
revision: u64,
|
|
items: Vec<CompletionItem>,
|
|
},
|
|
Message {
|
|
text: String,
|
|
},
|
|
Label {
|
|
name: String,
|
|
text: String,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct PluginUpdate {
|
|
pub request_id: Option<u64>,
|
|
pub effects: Vec<UpdateEffect>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum PluginEvent {
|
|
Response {
|
|
id: u64,
|
|
effects: Vec<crate::editor::Effect>,
|
|
},
|
|
Update(PluginUpdate),
|
|
}
|