1 module dls.protocol.interfaces.text_document;
2 
3 import dls.protocol.definitions;
4 import dls.protocol.interfaces.client : TextDocumentRegistrationOptions;
5 import dls.util.constructor : Constructor;
6 import std.json : JSONValue;
7 import std.typecons : Nullable;
8 
9 class DidOpenTextDocumentParams
10 {
11     TextDocumentItem textDocument;
12 
13     mixin Constructor!DidOpenTextDocumentParams;
14 }
15 
16 class DidChangeTextDocumentParams
17 {
18     VersionedTextDocumentIdentifier textDocument;
19     TextDocumentContentChangeEvent[] contentChanges;
20 
21     mixin Constructor!DidChangeTextDocumentParams;
22 }
23 
24 class TextDocumentContentChangeEvent
25 {
26     Nullable!Range range;
27     Nullable!size_t rangeLength;
28     string text;
29 }
30 
31 class TextDocumentChangeRegistrationOptions : TextDocumentRegistrationOptions
32 {
33     import dls.protocol.interfaces.general : TextDocumentSyncKind;
34 
35     TextDocumentSyncKind syncKind;
36 
37     this(TextDocumentSyncKind syncKind = TextDocumentSyncKind.init)
38     {
39         this.syncKind = syncKind;
40     }
41 }
42 
43 private class ParamsBase
44 {
45     TextDocumentIdentifier textDocument;
46 
47     mixin Constructor!ParamsBase;
48 }
49 
50 class WillSaveTextDocumentParams : ParamsBase
51 {
52     TextDocumentSaveReason reason;
53 }
54 
55 enum TextDocumentSaveReason
56 {
57     manual = 1,
58     afterDelay = 2,
59     focusOut = 3
60 }
61 
62 class DidSaveTextDocumentParams : ParamsBase
63 {
64     Nullable!string text;
65 }
66 
67 class TextDocumentSaveRegistrationOptions : TextDocumentRegistrationOptions
68 {
69     Nullable!bool includeText;
70 
71     this(Nullable!bool includeText = Nullable!bool.init)
72     {
73         this.includeText = includeText;
74     }
75 }
76 
77 alias DidCloseTextDocumentParams = ParamsBase;
78 
79 class PublishDiagnosticsParams
80 {
81     DocumentUri uri;
82     Diagnostic[] diagnostics;
83 
84     this(DocumentUri uri = DocumentUri.init, Diagnostic[] diagnostics = Diagnostic[].init)
85     {
86         this.uri = uri;
87         this.diagnostics = diagnostics;
88     }
89 }
90 
91 class CompletionParams : TextDocumentPositionParams
92 {
93     Nullable!CompletionContext context;
94 }
95 
96 class CompletionContext
97 {
98     CompletionTriggerKind triggerKind;
99     Nullable!string triggerCharacter;
100 }
101 
102 enum CompletionTriggerKind
103 {
104     invoked = 1,
105     triggerCharacter = 2,
106     triggerForIncompleteCompletions = 3
107 }
108 
109 class CompletionList
110 {
111     bool isIncomplete;
112     CompletionItem[] items;
113 
114     this(bool isIncomplete = bool.init, CompletionItem[] items = CompletionItem[].init)
115     {
116         this.isIncomplete = isIncomplete;
117         this.items = items;
118     }
119 }
120 
121 enum InsertTextFormat
122 {
123     plainText = 1,
124     snippet = 2
125 }
126 
127 class CompletionItem
128 {
129     string label;
130     Nullable!CompletionItemKind kind;
131     Nullable!string detail;
132     Nullable!MarkupContent documentation;
133     Nullable!bool deprecated_;
134     Nullable!string sortText;
135     Nullable!string filterText;
136     Nullable!string insertText;
137     Nullable!InsertTextFormat insertTextFormat;
138     Nullable!TextEdit textEdit;
139     Nullable!(TextEdit[]) additionalTextEdits;
140     Nullable!(string[]) commitCharacters;
141     Nullable!Command command;
142     Nullable!JSONValue data;
143 
144     this(string label = string.init, Nullable!CompletionItemKind kind = Nullable!CompletionItemKind.init,
145             Nullable!string detail = Nullable!string.init,
146             Nullable!MarkupContent documentation = Nullable!MarkupContent.init,
147             Nullable!bool deprecated_ = Nullable!bool.init, Nullable!string sortText = Nullable!string.init,
148             Nullable!string filterText = Nullable!string.init, Nullable!string insertText = Nullable!string.init,
149             Nullable!InsertTextFormat insertTextFormat = Nullable!InsertTextFormat.init,
150             Nullable!TextEdit textEdit = Nullable!TextEdit.init,
151             Nullable!(TextEdit[]) additionalTextEdits = Nullable!(TextEdit[])
152             .init, Nullable!(string[]) commitCharacters = Nullable!(string[])
153             .init, Nullable!Command command = Nullable!Command.init,
154             Nullable!JSONValue data = Nullable!JSONValue.init)
155     {
156         this.label = label;
157         this.kind = kind;
158         this.detail = detail;
159         this.documentation = documentation;
160         this.deprecated_ = deprecated_;
161         this.sortText = sortText;
162         this.filterText = filterText;
163         this.insertText = insertText;
164         this.insertTextFormat = insertTextFormat;
165         this.textEdit = textEdit;
166         this.additionalTextEdits = additionalTextEdits;
167         this.commitCharacters = commitCharacters;
168         this.command = command;
169         this.data = data;
170     }
171 }
172 
173 enum CompletionItemKind
174 {
175     text = 1,
176     method = 2,
177     function_ = 3,
178     constructor = 4,
179     field = 5,
180     variable = 6,
181     class_ = 7,
182     interface_ = 8,
183     module_ = 9,
184     property = 10,
185     unit = 11,
186     value = 12,
187     enum_ = 13,
188     keyword = 14,
189     snippet = 15,
190     color = 16,
191     file = 17,
192     reference = 18,
193     folder = 19,
194     enumMember = 20,
195     constant = 21,
196     struct_ = 22,
197     event = 23,
198     operator = 24,
199     typeParameter = 25
200 }
201 
202 class CompletionRegistrationOptions : TextDocumentRegistrationOptions
203 {
204     Nullable!(string[]) triggerCharacters;
205     Nullable!bool resolveProvider;
206 
207     this(Nullable!(string[]) triggerCharacters = Nullable!(string[]).init,
208             Nullable!bool resolveProvider = Nullable!bool.init)
209     {
210         this.triggerCharacters = triggerCharacters;
211         this.resolveProvider = resolveProvider;
212     }
213 }
214 
215 class Hover
216 {
217     MarkupContent contents;
218     Nullable!Range range;
219 
220     this(MarkupContent contents = MarkupContent.init, Nullable!Range range = Nullable!Range.init)
221     {
222         this.contents = contents;
223         this.range = range;
224     }
225 }
226 
227 class SignatureHelp
228 {
229     SignatureInformation[] signatures;
230     Nullable!double activeSignature;
231     Nullable!double activeParameter;
232 
233     this(SignatureInformation[] signatures = SignatureInformation[].init,
234             Nullable!double activeSignature = Nullable!double.init,
235             Nullable!double activeParameter = Nullable!double.init)
236     {
237         this.signatures = signatures;
238         this.activeSignature = activeSignature;
239         this.activeParameter = activeParameter;
240     }
241 }
242 
243 private class InformationBase
244 {
245     string label;
246     Nullable!string documentation;
247 }
248 
249 class SignatureInformation : InformationBase
250 {
251     Nullable!(ParameterInformation[]) parameters;
252 
253     this(Nullable!(ParameterInformation[]) parameters = Nullable!(ParameterInformation[]).init)
254     {
255         this.parameters = parameters;
256     }
257 }
258 
259 alias ParameterInformation = InformationBase;
260 
261 class SignatureHelpRegistrationOptions : TextDocumentRegistrationOptions
262 {
263     Nullable!(string[]) triggerCharacters;
264 
265     this(Nullable!(string[]) triggerCharacters = Nullable!(string[]).init)
266     {
267         this.triggerCharacters = triggerCharacters;
268     }
269 }
270 
271 class ReferenceParams : TextDocumentPositionParams
272 {
273     ReferenceContext context;
274 
275     mixin Constructor!ReferenceParams;
276 }
277 
278 class ReferenceContext
279 {
280     bool includeDeclaration;
281 }
282 
283 class DocumentHighlight
284 {
285     Range range;
286     Nullable!DocumentHighlightKind kind;
287 
288     this(Range range = new Range(),
289             Nullable!DocumentHighlightKind kind = Nullable!DocumentHighlightKind.init)
290     {
291         this.range = range;
292         this.kind = kind;
293     }
294 }
295 
296 enum DocumentHighlightKind
297 {
298     text = 1,
299     read = 2,
300     write = 3
301 }
302 
303 alias DocumentSymbolParams = ParamsBase;
304 
305 class SymbolInformation
306 {
307     string name;
308     SymbolKind kind;
309     Location location;
310     Nullable!string containerName;
311 
312     this(string name = string.init, SymbolKind kind = SymbolKind.init,
313             Location location = new Location(),
314             Nullable!string containerName = Nullable!string.init)
315     {
316         this.name = name;
317         this.kind = kind;
318         this.location = location;
319         this.containerName = containerName;
320     }
321 }
322 
323 enum SymbolKind
324 {
325     file = 1,
326     module_ = 2,
327     namespace = 3,
328     package_ = 4,
329     class_ = 5,
330     method = 6,
331     property = 7,
332     field = 8,
333     constructor = 9,
334     enum_ = 10,
335     interface_ = 11,
336     function_ = 12,
337     variable = 13,
338     constant = 14,
339     string_ = 15,
340     number = 16,
341     boolean = 17,
342     array = 18,
343     object = 19,
344     key = 20,
345     null_ = 21,
346     enumMember = 22,
347     struct_ = 23,
348     event = 24,
349     operator = 25,
350     typeParameter = 26
351 }
352 
353 class CodeActionParams : ParamsBase
354 {
355     Range range;
356     CodeActionContext context;
357 
358     mixin Constructor!CodeActionParams;
359 }
360 
361 class CodeActionContext
362 {
363     Diagnostic[] diagnostics;
364 }
365 
366 alias CodeLensParams = ParamsBase;
367 
368 class CodeLens
369 {
370     Range range;
371     Nullable!Command command;
372     Nullable!JSONValue data;
373 
374     this(Range range = new Range(), Nullable!Command command = Nullable!Command.init,
375             Nullable!JSONValue data = Nullable!JSONValue.init)
376     {
377         this.range = range;
378         this.command = command;
379         this.data = data;
380     }
381 }
382 
383 class CodeLensRegistrationOptions : TextDocumentRegistrationOptions
384 {
385     Nullable!bool resolveProvider;
386 
387     this(Nullable!bool resolveProvider = Nullable!bool.init)
388     {
389         this.resolveProvider = resolveProvider;
390     }
391 }
392 
393 alias DocumentLinkParams = ParamsBase;
394 
395 class DocumentLink
396 {
397     Range range;
398     Nullable!DocumentUri target;
399 
400     this(Range range = new Range(), Nullable!DocumentUri target = Nullable!DocumentUri.init)
401     {
402         this.range = range;
403         this.target = target;
404     }
405 }
406 
407 class DocumentLinkRegistrationOptions : TextDocumentRegistrationOptions
408 {
409     Nullable!bool resolveProvider;
410 
411     this(Nullable!bool resolveProvider = Nullable!bool.init)
412     {
413         this.resolveProvider = resolveProvider;
414     }
415 }
416 
417 class DocumentColorParams
418 {
419     TextDocumentIdentifier textDocument;
420 
421     mixin Constructor!DocumentColorParams;
422 }
423 
424 class ColorInformation
425 {
426     Range range;
427     Color color;
428 
429     this(Range range = new Range(), Color color = new Color())
430     {
431         this.range = range;
432         this.color = color;
433     }
434 }
435 
436 class Color
437 {
438     float red;
439     float green;
440     float blue;
441     float alpha;
442 
443     this(float red = 0, float green = 0, float blue = 0, float alpha = 0)
444     {
445         this.red = red;
446         this.green = green;
447         this.blue = blue;
448         this.alpha = alpha;
449     }
450 }
451 
452 class ColorPresentationParams
453 {
454     TextDocumentIdentifier textDocument;
455     Color colorInfo;
456     Range range;
457 
458     mixin Constructor!ColorPresentationParams;
459 }
460 
461 class ColorPresentation
462 {
463     string label;
464     Nullable!TextEdit textEdit;
465     Nullable!(TextEdit[]) additionalTextEdits;
466 
467     this(string label = string.init, Nullable!TextEdit textEdit = Nullable!TextEdit.init,
468             Nullable!(TextEdit[]) additionalTextEdits = Nullable!(TextEdit[]).init)
469     {
470         this.label = label;
471         this.textEdit = textEdit;
472         this.additionalTextEdits = additionalTextEdits;
473     }
474 }
475 
476 class DocumentFormattingParams : ParamsBase
477 {
478     FormattingOptions options;
479 
480     mixin Constructor!DocumentFormattingParams;
481 }
482 
483 class FormattingOptions
484 {
485     size_t tabSize;
486     bool insertSpaces;
487 }
488 
489 class DocumentRangeFormattingParams : DocumentFormattingParams
490 {
491     Range range;
492 
493     mixin Constructor!DocumentRangeFormattingParams;
494 }
495 
496 class DocumentOnTypeFormattingParams : DocumentFormattingParams
497 {
498     Position position;
499     string ch;
500 
501     mixin Constructor!DocumentOnTypeFormattingParams;
502 }
503 
504 class DocumentOnTypeFormattingRegistrationOptions : TextDocumentRegistrationOptions
505 {
506     string firstTriggerCharacter;
507     Nullable!(string[]) moreTriggerCharacter;
508 
509     this(string firstTriggerCharacter = string.init,
510             Nullable!(string[]) moreTriggerCharacter = Nullable!(string[]).init)
511     {
512         this.firstTriggerCharacter = firstTriggerCharacter;
513         this.moreTriggerCharacter = moreTriggerCharacter;
514     }
515 }
516 
517 class RenameParams : ParamsBase
518 {
519     Position position;
520     string newName;
521 
522     mixin Constructor!RenameParams;
523 }