1use oak_core::{Arc, Range, language::UniversalElementRole};
2pub use oak_folding::FoldingRange;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub struct LspRange {
8 pub start: usize,
10 pub end: usize,
12}
13
14impl From<Range<usize>> for LspRange {
15 fn from(range: Range<usize>) -> Self {
16 Self { start: range.start, end: range.end }
17 }
18}
19
20impl From<LspRange> for Range<usize> {
21 fn from(range: LspRange) -> Self {
22 Self { start: range.start, end: range.end }
23 }
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[cfg_attr(feature = "serde", serde(bound(serialize = "R: serde::Serialize", deserialize = "R: serde::Deserialize<'de>")))]
30pub struct Location<R = Range<usize>> {
31 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_arc_str"))]
33 pub uri: Arc<str>,
34 pub range: R,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Hash)]
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41pub struct LocationRange {
42 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_arc_str"))]
44 pub uri: Arc<str>,
45 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
47 pub range: Range<usize>,
48}
49
50impl From<LocationRange> for Location<Range<usize>> {
51 fn from(loc: LocationRange) -> Self {
52 Self { uri: loc.uri, range: loc.range }
53 }
54}
55
56impl From<Location<Range<usize>>> for LocationRange {
57 fn from(loc: Location<Range<usize>>) -> Self {
58 Self { uri: loc.uri, range: loc.range }
59 }
60}
61
62impl From<oak_navigation::Location> for Location<Range<usize>> {
63 fn from(loc: oak_navigation::Location) -> Self {
64 Self { uri: loc.uri, range: loc.range }
65 }
66}
67
68impl From<oak_navigation::Location> for LocationRange {
69 fn from(loc: oak_navigation::Location) -> Self {
70 Self { uri: loc.uri, range: loc.range }
71 }
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
76#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
77pub struct SourcePosition {
78 pub line: u32,
80 pub column: u32,
82 pub offset: usize,
84 pub length: usize,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Hash)]
90#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
91pub struct SourceLocation {
92 pub line: u32,
94 pub column: u32,
96 pub url: Option<url::Url>,
98}
99
100impl Default for SourceLocation {
101 fn default() -> Self {
103 Self { line: 1, column: 1, url: None }
104 }
105}
106
107#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub enum DocumentHighlightKind {
111 Text = 1,
113 Read = 2,
115 Write = 3,
117}
118
119#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
121#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
122pub struct DocumentHighlight {
123 pub range: LspRange,
125 pub kind: Option<DocumentHighlightKind>,
127}
128
129#[derive(Debug, Clone, Copy, PartialEq)]
131#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
132pub struct Color {
133 pub red: f32,
135 pub green: f32,
137 pub blue: f32,
139 pub alpha: f32,
141}
142
143#[derive(Debug, Clone, Copy, PartialEq)]
145#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
146pub struct ColorInformation {
147 pub range: LspRange,
149 pub color: Color,
151}
152
153#[derive(Debug, Clone)]
155#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
156pub struct Hover {
157 pub contents: String,
159 #[cfg_attr(feature = "serde", serde(with = "serde_range_opt"))]
161 pub range: Option<Range<usize>>,
162}
163
164#[cfg(feature = "serde")]
165mod serde_range_opt {
166 use super::*;
167 use serde::{Deserialize, Deserializer, Serializer};
168
169 pub fn serialize<S>(value: &Option<Range<usize>>, serializer: S) -> Result<S::Ok, S::Error>
170 where
171 S: Serializer,
172 {
173 match value {
174 Some(range) => oak_core::serde_range::serialize(range, serializer),
175 None => serializer.serialize_none(),
176 }
177 }
178
179 #[derive(Deserialize)]
180 struct RangeDef {
181 start: usize,
182 end: usize,
183 }
184
185 pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Range<usize>>, D::Error>
186 where
187 D: Deserializer<'de>,
188 {
189 let opt: Option<RangeDef> = Option::deserialize(deserializer)?;
190 Ok(opt.map(|def| Range { start: def.start, end: def.end }))
191 }
192}
193
194#[derive(Debug, Clone)]
196#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
197pub struct StructureItem {
198 pub name: String,
200 pub detail: Option<String>,
202 pub role: UniversalElementRole,
204 pub kind: SymbolKind,
206 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
208 pub range: Range<usize>,
209 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
212 pub selection_range: Range<usize>,
213 pub deprecated: bool,
215 pub children: Vec<StructureItem>,
217}
218
219#[derive(Debug, Clone, Default)]
221#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
222pub struct InitializeParams {
223 pub root_uri: Option<String>,
225 pub workspace_folders: Vec<WorkspaceFolder>,
227}
228
229#[derive(Debug, Clone)]
231#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
232pub struct WorkspaceFolder {
233 pub uri: String,
235 pub name: String,
237}
238
239#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
241#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
242pub enum SymbolKind {
243 File = 1,
245 Module = 2,
247 Namespace = 3,
249 Package = 4,
251 Class = 5,
253 Method = 6,
255 Property = 7,
257 Field = 8,
259 Constructor = 9,
261 Enum = 10,
263 Interface = 11,
265 Function = 12,
267 Variable = 13,
269 Constant = 14,
271 String = 15,
273 Number = 16,
275 Boolean = 17,
277 Array = 18,
279 Object = 19,
281 Key = 20,
283 Null = 21,
285 EnumMember = 22,
287 Struct = 23,
289 Event = 24,
291 Operator = 25,
293 TypeParameter = 26,
295}
296
297#[derive(Debug, Clone)]
299#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
300pub struct WorkspaceSymbol {
301 pub name: String,
303 pub kind: SymbolKind,
305 pub location: LocationRange,
307 pub container_name: Option<String>,
309}
310
311#[derive(Debug, Clone)]
313#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
314pub struct SymbolInformation {
315 pub name: String,
317 pub kind: SymbolKind,
319 pub location: LocationRange,
321 pub container_name: Option<String>,
323}
324
325#[derive(Debug, Clone, Default)]
327#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
328pub struct WorkspaceEdit {
329 pub changes: std::collections::HashMap<String, Vec<TextEdit>>,
331}
332
333#[derive(Debug, Clone)]
335#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
336pub struct TextEdit {
337 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
339 pub range: Range<usize>,
340 pub new_text: String,
342}
343
344#[derive(Debug, Clone)]
346#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
347pub struct CompletionItem {
348 pub label: String,
350 pub kind: Option<CompletionItemKind>,
352 pub detail: Option<String>,
354 pub documentation: Option<String>,
356 pub insert_text: Option<String>,
358}
359
360#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
362#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
363pub enum CompletionItemKind {
364 Text = 1,
366 Method = 2,
368 Function = 3,
370 Constructor = 4,
372 Field = 5,
374 Variable = 6,
376 Class = 7,
378 Interface = 8,
380 Module = 9,
382 Property = 10,
384 Unit = 11,
386 Value = 12,
388 Enum = 13,
390 Keyword = 14,
392 Snippet = 15,
394 Color = 16,
396 File = 17,
398 Reference = 18,
400 Folder = 19,
402 EnumMember = 20,
404 Constant = 21,
406 Struct = 22,
408 Event = 23,
410 Operator = 24,
412 TypeParameter = 25,
414}
415
416#[derive(Debug, Clone)]
418#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
419pub struct Diagnostic {
420 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
422 pub range: Range<usize>,
423 pub severity: Option<DiagnosticSeverity>,
425 pub code: Option<String>,
427 pub source: Option<String>,
429 pub message: String,
431}
432
433#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
435#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
436pub enum DiagnosticSeverity {
437 Error = 1,
439 Warning = 2,
441 Information = 3,
443 Hint = 4,
445}
446
447#[derive(Debug, Clone)]
449#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
450pub struct SemanticToken {
451 pub delta_line: u32,
453 pub delta_start: u32,
455 pub length: u32,
457 pub token_type: u32,
459 pub token_modifiers_bitset: u32,
461}
462
463#[derive(Debug, Clone)]
465#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
466pub struct SemanticTokens {
467 pub result_id: Option<String>,
469 pub data: Vec<SemanticToken>,
471}
472
473#[derive(Debug, Clone)]
475#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
476pub struct SelectionRange {
477 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
479 pub range: Range<usize>,
480 pub parent: Option<Box<SelectionRange>>,
482}
483
484#[derive(Debug, Clone)]
486#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
487pub struct ParameterInformation {
488 pub label: String,
490 pub documentation: Option<String>,
492}
493
494#[derive(Debug, Clone)]
496#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
497pub struct SignatureInformation {
498 pub label: String,
500 pub documentation: Option<String>,
502 pub parameters: Option<Vec<ParameterInformation>>,
504 pub active_parameter: Option<u32>,
506}
507
508#[derive(Debug, Clone)]
510#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
511pub struct SignatureHelp {
512 pub signatures: Vec<SignatureInformation>,
514 pub active_signature: Option<u32>,
516 pub active_parameter: Option<u32>,
518}
519
520#[derive(Debug, Clone)]
522#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
523pub struct InlayHint {
524 pub position: SourcePosition,
526 pub label: String,
528 pub kind: Option<InlayHintKind>,
530 pub tooltip: Option<String>,
532 pub padding_left: Option<bool>,
534 pub padding_right: Option<bool>,
536}
537
538#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
540#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
541pub enum InlayHintKind {
542 Type = 1,
544 Parameter = 2,
546}
547
548#[derive(Debug, Clone)]
550#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
551pub struct CodeAction {
552 pub title: String,
554 pub kind: Option<String>,
556 pub diagnostics: Option<Vec<Diagnostic>>,
558 pub edit: Option<WorkspaceEdit>,
560 pub command: Option<Command>,
562 pub is_preferred: Option<bool>,
564 pub disabled: Option<CodeActionDisabled>,
566}
567
568#[derive(Debug, Clone)]
570#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
571pub struct CodeActionDisabled {
572 pub reason: String,
574}
575
576#[derive(Debug, Clone)]
578#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
579pub struct Command {
580 pub title: String,
582 pub command: String,
584 pub arguments: Option<Vec<serde_json::Value>>,
586}
587
588impl From<UniversalElementRole> for SymbolKind {
589 fn from(role: UniversalElementRole) -> Self {
590 match role {
591 UniversalElementRole::Root => SymbolKind::File,
592 UniversalElementRole::Container => SymbolKind::Module,
593 UniversalElementRole::Definition => SymbolKind::Function,
594 UniversalElementRole::Binding => SymbolKind::Variable,
595 UniversalElementRole::Reference => SymbolKind::Variable,
596 UniversalElementRole::Typing => SymbolKind::Class,
597 UniversalElementRole::Statement => SymbolKind::Function,
598 UniversalElementRole::Expression => SymbolKind::Variable,
599 UniversalElementRole::Call => SymbolKind::Function,
600 UniversalElementRole::Metadata => SymbolKind::Property,
601 UniversalElementRole::Attribute => SymbolKind::Property,
602 UniversalElementRole::Documentation => SymbolKind::String,
603 UniversalElementRole::Value => SymbolKind::Constant,
604 UniversalElementRole::Error => SymbolKind::Null,
605 _ => SymbolKind::Function,
606 }
607 }
608}
609
610impl From<oak_symbols::SymbolInformation> for WorkspaceSymbol {
611 fn from(s: oak_symbols::SymbolInformation) -> Self {
612 Self { name: s.name, kind: SymbolKind::from(s.role), location: LocationRange { uri: s.uri, range: s.range }, container_name: s.container_name }
613 }
614}
615
616impl From<oak_symbols::SymbolInformation> for StructureItem {
617 fn from(s: oak_symbols::SymbolInformation) -> Self {
618 Self { name: s.name, detail: None, role: s.role, kind: SymbolKind::from(s.role), range: s.range.clone(), selection_range: s.range.clone(), deprecated: false, children: vec![] }
619 }
620}