1 module dls.protocol.definitions;
2 
3 import std.json : JSONValue;
4 import std.typecons : Nullable, nullable;
5 import dls.util.constructor : Constructor;
6 
7 alias DocumentUri = string;
8 
9 class Position
10 {
11     size_t line;
12     size_t character;
13 
14     this(size_t line = size_t.init, size_t character = size_t.init)
15     {
16         this.line = line;
17         this.character = character;
18     }
19 }
20 
21 class Range
22 {
23     Position start;
24     Position end;
25 
26     this(Position start = new Position(), Position end = new Position())
27     {
28         this.start = start;
29         this.end = end;
30     }
31 }
32 
33 class Location
34 {
35     DocumentUri uri;
36     Range range;
37 
38     this(DocumentUri uri = DocumentUri.init, Range range = new Range())
39     {
40         this.uri = uri;
41         this.range = range;
42     }
43 }
44 
45 class Diagnostic
46 {
47     Range range;
48     string message;
49     Nullable!DiagnosticSeverity severity;
50     Nullable!JSONValue code;
51     Nullable!string source;
52     Nullable!(DiagnosticRelatedInformation[]) relatedInformation;
53 
54     this(Range range = new Range(), string message = string.init,
55             Nullable!DiagnosticSeverity severity = Nullable!DiagnosticSeverity.init,
56             Nullable!JSONValue code = Nullable!JSONValue.init,
57             Nullable!string source = Nullable!string.init,
58             Nullable!(DiagnosticRelatedInformation[]) relatedInformation = Nullable!(
59                 DiagnosticRelatedInformation[]).init)
60     {
61         this.range = range;
62         this.message = message;
63         this.severity = severity;
64         this.code = code;
65         this.source = source;
66         this.relatedInformation = relatedInformation;
67     }
68 }
69 
70 enum DiagnosticSeverity
71 {
72     error = 1,
73     warning = 2,
74     information = 3,
75     hint = 4
76 }
77 
78 class DiagnosticRelatedInformation
79 {
80     Location location;
81     string message;
82 
83     this(Location location = new Location(), string message = string.init)
84     {
85         this.location = location;
86         this.message = message;
87     }
88 }
89 
90 class Command
91 {
92     string title;
93     string command;
94     Nullable!(JSONValue[]) arguments;
95 
96     this(string title = string.init, string command = string.init,
97             Nullable!(JSONValue[]) arguments = Nullable!(JSONValue[]).init)
98     {
99         this.title = title;
100         this.command = command;
101         this.arguments = arguments;
102     }
103 }
104 
105 class TextEdit
106 {
107     Range range;
108     string newText;
109 
110     this(Range range = new Range(), string newText = string.init)
111     {
112         this.range = range;
113         this.newText = newText;
114     }
115 }
116 
117 class TextDocumentEdit
118 {
119     VersionedTextDocumentIdentifier textDocument;
120     TextEdit[] edits;
121 
122     this(VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(),
123             TextEdit[] edits = TextEdit[].init)
124     {
125         this.textDocument = textDocument;
126         this.edits = edits;
127     }
128 }
129 
130 class WorkspaceEdit
131 {
132     Nullable!((TextEdit[])[string]) changes;
133     Nullable!(TextDocumentEdit[]) documentChanges;
134 
135     this(Nullable!((TextEdit[])[string]) changes = Nullable!((TextEdit[])[string]).init,
136             Nullable!(TextDocumentEdit[]) documentChanges = Nullable!(TextDocumentEdit[]).init)
137     {
138         this.changes = changes;
139         this.documentChanges = documentChanges;
140     }
141 }
142 
143 class TextDocumentIdentifier
144 {
145     DocumentUri uri;
146 }
147 
148 class TextDocumentItem
149 {
150     DocumentUri uri;
151     string languageId;
152     ulong version_;
153     string text;
154 }
155 
156 class VersionedTextDocumentIdentifier : TextDocumentIdentifier
157 {
158     ulong version_;
159 }
160 
161 class TextDocumentPositionParams
162 {
163     TextDocumentIdentifier textDocument;
164     Position position;
165 
166     mixin Constructor!TextDocumentPositionParams;
167 }
168 
169 class DocumentFilter
170 {
171     Nullable!string languageId;
172     Nullable!string scheme;
173     Nullable!string pattern;
174 
175     this(Nullable!string languageId = Nullable!string.init,
176             Nullable!string scheme = Nullable!string.init,
177             Nullable!string pattern = Nullable!string.init)
178     {
179         this.languageId = languageId;
180         this.scheme = scheme;
181         this.pattern = pattern;
182     }
183 }
184 
185 alias DocumentSelector = DocumentFilter[];
186 
187 enum MarkupKind
188 {
189     plaintext = "plaintext",
190     markdown = "markdown"
191 }
192 
193 class MarkupContent
194 {
195     MarkupKind kind;
196     string value;
197 
198     this(MarkupKind kind = MarkupKind.init, string value = string.init)
199     {
200         this.kind = kind;
201         this.value = value;
202     }
203 }