Skip to main content

daytona_client/models/
lsp.rs

1//! Language Server Protocol models
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// LSP initialization parameters
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct LspInitializeParams {
10    pub root_uri: String,
11    pub language: String,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub workspace_folders: Option<Vec<WorkspaceFolder>>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub initialization_options: Option<Value>,
16}
17
18/// Workspace folder
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct WorkspaceFolder {
22    pub uri: String,
23    pub name: String,
24}
25
26/// Text document position
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct TextDocumentPosition {
30    pub text_document: TextDocumentIdentifier,
31    pub position: Position,
32}
33
34/// Text document identifier
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct TextDocumentIdentifier {
38    pub uri: String,
39}
40
41/// Position in a document
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct Position {
45    pub line: u32,
46    pub character: u32,
47}
48
49/// Range in a document
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct Range {
53    pub start: Position,
54    pub end: Position,
55}
56
57/// Location in a document
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct Location {
61    pub uri: String,
62    pub range: Range,
63}
64
65/// Completion item
66#[derive(Debug, Clone, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct CompletionItem {
69    pub label: String,
70    pub kind: Option<CompletionItemKind>,
71    pub detail: Option<String>,
72    pub documentation: Option<String>,
73    pub insert_text: Option<String>,
74    pub insert_text_format: Option<InsertTextFormat>,
75    pub additional_text_edits: Option<Vec<TextEdit>>,
76}
77
78/// Completion item kind
79#[derive(Debug, Clone, Copy, Deserialize)]
80#[repr(u8)]
81pub enum CompletionItemKind {
82    Text = 1,
83    Method = 2,
84    Function = 3,
85    Constructor = 4,
86    Field = 5,
87    Variable = 6,
88    Class = 7,
89    Interface = 8,
90    Module = 9,
91    Property = 10,
92    Unit = 11,
93    Value = 12,
94    Enum = 13,
95    Keyword = 14,
96    Snippet = 15,
97    Color = 16,
98    File = 17,
99    Reference = 18,
100    Folder = 19,
101    EnumMember = 20,
102    Constant = 21,
103    Struct = 22,
104    Event = 23,
105    Operator = 24,
106    TypeParameter = 25,
107}
108
109/// Insert text format
110#[derive(Debug, Clone, Copy, Deserialize)]
111#[repr(u8)]
112pub enum InsertTextFormat {
113    PlainText = 1,
114    Snippet = 2,
115}
116
117/// Text edit
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120pub struct TextEdit {
121    pub range: Range,
122    pub new_text: String,
123}
124
125/// Diagnostic
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(rename_all = "camelCase")]
128pub struct Diagnostic {
129    pub range: Range,
130    pub severity: DiagnosticSeverity,
131    pub code: Option<String>,
132    pub source: Option<String>,
133    pub message: String,
134    pub related_information: Option<Vec<DiagnosticRelatedInformation>>,
135}
136
137/// Diagnostic severity
138#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
139#[repr(u8)]
140pub enum DiagnosticSeverity {
141    Error = 1,
142    Warning = 2,
143    Information = 3,
144    Hint = 4,
145}
146
147/// Diagnostic related information
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct DiagnosticRelatedInformation {
151    pub location: Location,
152    pub message: String,
153}
154
155/// Hover information
156#[derive(Debug, Clone, Deserialize)]
157#[serde(rename_all = "camelCase")]
158pub struct Hover {
159    pub contents: HoverContents,
160    pub range: Option<Range>,
161}
162
163/// Hover contents
164#[derive(Debug, Clone, Deserialize)]
165#[serde(untagged)]
166pub enum HoverContents {
167    PlainText(String),
168    Markdown(MarkupContent),
169    MarkedStrings(Vec<MarkedString>),
170}
171
172/// Markup content
173#[derive(Debug, Clone, Deserialize)]
174#[serde(rename_all = "camelCase")]
175pub struct MarkupContent {
176    pub kind: MarkupKind,
177    pub value: String,
178}
179
180/// Markup kind
181#[derive(Debug, Clone, Deserialize)]
182#[serde(rename_all = "lowercase")]
183pub enum MarkupKind {
184    PlainText,
185    Markdown,
186}
187
188/// Marked string
189#[derive(Debug, Clone, Deserialize)]
190#[serde(untagged)]
191pub enum MarkedString {
192    String(String),
193    LanguageString { language: String, value: String },
194}
195
196/// Symbol information
197#[derive(Debug, Clone, Deserialize)]
198#[serde(rename_all = "camelCase")]
199pub struct SymbolInformation {
200    pub name: String,
201    pub kind: SymbolKind,
202    pub location: Location,
203    pub container_name: Option<String>,
204}
205
206/// Symbol kind
207#[derive(Debug, Clone, Copy, Deserialize)]
208#[repr(u8)]
209pub enum SymbolKind {
210    File = 1,
211    Module = 2,
212    Namespace = 3,
213    Package = 4,
214    Class = 5,
215    Method = 6,
216    Property = 7,
217    Field = 8,
218    Constructor = 9,
219    Enum = 10,
220    Interface = 11,
221    Function = 12,
222    Variable = 13,
223    Constant = 14,
224    String = 15,
225    Number = 16,
226    Boolean = 17,
227    Array = 18,
228    Object = 19,
229    Key = 20,
230    Null = 21,
231    EnumMember = 22,
232    Struct = 23,
233    Event = 24,
234    Operator = 25,
235    TypeParameter = 26,
236}
237
238/// Code action
239#[derive(Debug, Clone, Deserialize)]
240#[serde(rename_all = "camelCase")]
241pub struct CodeAction {
242    pub title: String,
243    pub kind: Option<CodeActionKind>,
244    pub diagnostics: Option<Vec<Diagnostic>>,
245    pub edit: Option<WorkspaceEdit>,
246    pub command: Option<Command>,
247}
248
249/// Code action kind
250#[derive(Debug, Clone, Deserialize)]
251pub struct CodeActionKind(pub String);
252
253impl CodeActionKind {
254    pub const QUICKFIX: &'static str = "quickfix";
255    pub const REFACTOR: &'static str = "refactor";
256    pub const REFACTOR_EXTRACT: &'static str = "refactor.extract";
257    pub const REFACTOR_INLINE: &'static str = "refactor.inline";
258    pub const REFACTOR_REWRITE: &'static str = "refactor.rewrite";
259    pub const SOURCE: &'static str = "source";
260    pub const SOURCE_ORGANIZE_IMPORTS: &'static str = "source.organizeImports";
261}
262
263/// Workspace edit
264#[derive(Debug, Clone, Deserialize)]
265#[serde(rename_all = "camelCase")]
266pub struct WorkspaceEdit {
267    pub changes: Option<std::collections::HashMap<String, Vec<TextEdit>>>,
268}
269
270/// Command
271#[derive(Debug, Clone, Serialize, Deserialize)]
272#[serde(rename_all = "camelCase")]
273pub struct Command {
274    pub title: String,
275    pub command: String,
276    pub arguments: Option<Vec<Value>>,
277}