src/Lsp.vala
[roobuilder] / src / Lsp.vala
1 /* protocol.vala
2  *
3  * Copyright 2017-2019 Ben Iofel <ben@iofel.me>
4  * Copyright 2017-2020 Princeton Ferro <princetonferro@gmail.com>
5  * Copyright 2020 Sergii Fesenko <s.fesenko@outlook.com>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 2.1 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 namespace Lsp {
22     /**
23      * Defines how the host (editor) should sync document changes to the language server.
24      */
25     [CCode (default_value = "LSP_TEXT_DOCUMENT_SYNC_KIND_Unset")]
26     public enum TextDocumentSyncKind {
27         Unset = -1,
28         /**
29          * Documents should not be synced at all.
30          */
31         None = 0,
32         /**
33          * Documents are synced by always sending the full content of the document.
34          */
35         Full = 1,
36         /**
37          * Documents are synced by sending the full content on open. After that only incremental
38          * updates to the document are sent.
39          */
40         Incremental = 2
41     }
42
43     public  enum DiagnosticSeverity {
44         Unset = 0,
45         /**
46          * Reports an error.
47          */
48         Error = 1,
49         /**
50          * Reports a warning.
51          */
52         Warning = 2,
53         /**
54          * Reports an information.
55          */
56         Information = 3,
57         /**
58          * Reports a hint.
59          */
60         Hint = 4
61         
62     }
63
64     public  class Position : Object, Gee.Comparable<Position> {
65         /**
66          * Line position in a document (zero-based).
67          */
68         public uint line { get; set; default = -1; }
69
70         /**
71          * Character offset on a line in a document (zero-based). Assuming that the line is
72          * represented as a string, the `character` value represents the gap between the
73          * `character` and `character + 1`.
74          *
75          * If the character value is greater than the line length it defaults back to the
76          * line length.
77          */
78         public uint character { get; set; default = -1; }
79
80         public int compare_to (Position other) {
81             return line > other.line ? 1 :
82                 (line == other.line ?
83                  (character > other.character ? 1 :
84                   (character == other.character ? 0 : -1)) : -1);
85         }
86         public bool equals(Position o) {
87                 return o.line == this.line && o.character == this.character;
88         }
89                 
90         public string to_string () {
91             return @"$line:$character";
92         }
93
94         public Position.from_libvala (Vala.SourceLocation sloc) {
95             line = sloc.line - 1;
96             character = sloc.column;
97         }
98
99         public Position dup () {
100             return this.translate ();
101         }
102
103         public Position translate (int dl = 0, int dc = 0) {
104             return new Position () {
105                 line = this.line + dl,
106                 character = this.character + dc
107             };
108         }
109     }
110
111     public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
112         
113         public Range.simple(uint line, uint pos) {
114                 var p =  new Position () {
115                 line = line,
116                 character = pos
117             };
118                 this.start = p;
119                 this.end = p;
120                 
121         }
122         /**
123          * The range's start position.
124          */
125         public Position start { get; set; }
126
127         /**
128          * The range's end position.
129          */
130         public Position end { get; set; }
131
132         private string? filename;
133
134         public string to_string () { return (filename != null ? @"$filename:" : "") + @"$start -> $end"; }
135
136         public Range.from_pos (Position pos) {
137             this.start = pos;
138             this.end = pos.dup ();
139         }
140
141         public Range.from_sourceref (Vala.SourceReference sref) {
142             this.start = new Position.from_libvala (sref.begin);
143             this.end = new Position.from_libvala (sref.end);
144             this.start.character -= 1;
145             this.filename = sref.file.filename;
146         }
147
148         public uint hash () {
149             return this.to_string ().hash ();
150         }
151
152         public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
153                 public bool equals (Range o) {
154                         return this.filename == o.filename && this.start.equals(o.start) && this.end.equals(o.end);
155                 }
156
157         public int compare_to (Range other) {
158             return start.compare_to (other.start);
159         }
160
161         /**
162          * Return a new range that includes `this` and `other`.
163          */
164         public Range union (Range other) {
165             var range = new Range () {
166                 start = start.compare_to (other.start) < 0 ? start : other.start,
167                 end = end.compare_to (other.end) < 0 ? other.end : end,
168             };
169             if (filename == other.filename)
170                 range.filename = filename;
171             return range;
172         }
173
174         public bool contains (Position pos) {
175             return start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
176         }
177        
178     }
179
180     public class Diagnostic : Object {
181         
182         public Diagnostic.simple ( int line, int character, string message)
183         {
184                 this.message = message;
185                 this.severity = DiagnosticSeverity.Error;
186                 this.range =  new Range.simple(line, character );
187                 
188                 
189         
190         }
191         /**
192          * The range at which the message applies.
193          */
194         public Range range { get; set; }
195
196         /**
197          * The diagnostic's severity. Can be omitted. If omitted it is up to the
198          * client to interpret diagnostics as error, warning, info or hint.
199          */
200         public DiagnosticSeverity severity { get; set; }
201
202         /**
203          * The diagnostic's code. Can be omitted.
204          */
205         public string? code { get; set; }
206
207         /**
208          * A human-readable string describing the source of this
209          * diagnostic, e.g. 'typescript' or 'super lint'.
210          */
211         public string? source { get; set; }
212
213         /**
214          * The diagnostic's message.
215          */
216         public string message { get; set; }
217         
218         
219         public string category {
220                 get { 
221                         switch(this.severity) {
222
223                                 case DiagnosticSeverity.Error : 
224                                         return "ERR";
225                                 case DiagnosticSeverity.Warning : 
226                                         return this.message.contains("deprecated") ? "DEPR" : "WARN";
227                                 default : 
228                                         return "WARN";
229                         }
230                 }
231                 private set {}
232                 
233         }
234         public bool equals(Lsp.Diagnostic o) {
235                 var ret = this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
236                 //GLib.debug("compare %s  (%s == %s)", ret ? "YES" : "NO", this.to_string(), o.to_string()); 
237                 
238                 
239                 return ret;
240         }
241         public string to_string()
242         {
243                 return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
244         }
245         
246     }
247
248     /**
249      * An event describing a change to a text document. If range and rangeLength are omitted
250      * the new text is considered to be the full content of the document.
251      */
252     public class TextDocumentContentChangeEvent : Object {
253         public Range? range    { get; set; }
254         public int rangeLength { get; set; }
255         public string text     { get; set; }
256     }
257
258     public enum MessageType {
259         /**
260          * An error message.
261          */
262         Error = 1,
263         /**
264          * A warning message.
265          */
266         Warning = 2,
267         /**
268          * An information message.
269          */
270         Info = 3,
271         /**
272          * A log message.
273          */
274         Log = 4
275     }
276
277     public class TextDocumentIdentifier : Object {
278         public string uri { get; set; }
279     }
280
281     public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
282         /**
283          * The version number of this document. If a versioned text document identifier
284          * is sent from the server to the client and the file is not open in the editor
285          * (the server has not received an open notification before) the server can send
286          * `null` to indicate that the version is known and the content on disk is the
287          * master (as speced with document content ownership).
288          *
289          * The version number of a document will increase after each change, including
290          * undo/redo. The number doesn't need to be consecutive.
291          */
292         public int version { get; set; default = -1; }
293     }
294
295     public class TextDocumentPositionParams : Object {
296         public TextDocumentIdentifier textDocument { get; set; }
297         public Position position { get; set; }
298     }
299
300     public class ReferenceParams : TextDocumentPositionParams {
301         public class ReferenceContext : Object {
302             public bool includeDeclaration { get; set; }
303         }
304         public ReferenceContext? context { get; set; }
305     }
306
307     public class Location : Object {
308         public string uri { get; set; }
309         public Range range { get; set; }
310
311         public Location.from_sourceref (Vala.SourceReference sref) {
312             this (sref.file.filename, new Range.from_sourceref (sref));
313         }
314
315         public Location (string filename, Range range) {
316             this.uri = File.new_for_commandline_arg (filename).get_uri ();
317             this.range = range;
318         }
319     }
320
321     [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
322     public enum DocumentHighlightKind {
323         Text = 1,
324         Read = 2,
325         Write = 3
326     }
327
328     public class DocumentHighlight : Object {
329         public Range range { get; set; }
330         public DocumentHighlightKind kind { get; set; }
331     }
332
333     public class DocumentSymbolParams: Object {
334         public TextDocumentIdentifier textDocument { get; set; }
335     }
336
337     public class DocumentSymbol : Object, Json.Serializable {
338         private Vala.SourceReference? _source_reference;
339         public string name { get; set; }
340         public string? detail { get; set; }
341         public SymbolKind kind { get; set; }
342         public bool deprecated { get; set; }
343         private Range? _initial_range;
344         public Range range {
345             owned get {
346                 if (_initial_range == null)
347                     _initial_range = new Range.from_sourceref (children.first ()._source_reference);
348                 
349                 return children.fold<Range> ((child, current_range) => current_range.union (child.range), _initial_range);
350             }
351         }
352         public Range selectionRange { get; set; }
353         public GLib.ListStore children { get; private set; default = new Glib.ListStore(typeof(DocumentSymbol)); }
354         public string? parent_name;
355
356         private DocumentSymbol () {}
357
358         /**
359          * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
360          * @param sym the symbol
361          */
362          /*
363         public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
364             this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
365             this._initial_range = new Range.from_sourceref (sym.source_reference);
366             if (sym is Vala.Subroutine) {
367                 var sub = (Vala.Subroutine) sym;
368                 var body_sref = sub.body != null ? sub.body.source_reference : null;
369                 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
370                 //         body_sref != null ? body_sref.to_string () : null);
371                 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
372                                 val = GLib.Value (typeof(Gee.ArrayList));                          body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
373                     this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
374                 }
375             }
376             this.name = sym.name;
377             this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
378             this.kind = kind;
379             this.selectionRange = new Range.from_sourceref (sym.source_reference);
380             this.deprecated = sym.version.deprecated;
381         }
382         */
383         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
384             base.set_property (pspec.get_name (), value);
385         }
386
387         public new Value Json.Serializable.get_property (ParamSpec pspec) {
388             Value val = Value (pspec.value_type);
389             base.get_property (pspec.get_name (), ref val);
390             return val;
391         }
392
393         public unowned ParamSpec? find_property (string name) {
394             return this.get_class ().find_property (name);
395         }
396
397         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
398            // if (property_name != "children")
399                 return default_serialize_property (property_name, value, pspec);
400             /*var node = new Json.Node (Json.NodeType.ARRAY);
401             node.init_array (new Json.Array ());
402             var array = node.get_array ();
403             foreach (var child in children)
404                 array.add_element (Json.gobject_serialize (child));
405             return node;
406             */
407         }
408
409         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
410             {
411                 
412                 if (property_name != "children") {
413                     return default_deserialize_property (property_name, out value, pspec, property_node);
414                 }
415             value = GLib.Value (typeof(GLib.ListStore));
416                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
417                     warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
418                     return false;
419                 }
420                          
421                 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
422
423                 property_node.get_array ().foreach_element ((array, index, element) => {
424                     
425                         var add= Json.gobject_deserialize ( typeof (DocumentSymbol),  array.get_element(index)) as DocumentSymbol;
426                                 arguments.append( add);
427
428                    
429                 });
430
431                 value.set_object (arguments);
432                 return true;
433            }
434     }
435
436     public class SymbolInformation : Object {
437         public string name { get; set; }
438         public SymbolKind kind { get; set; }
439         public Location location { get; set; }
440         public string? containerName { get; set; }
441
442         public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
443             this.name = dsym.name;
444             this.kind = dsym.kind;
445             this.location = new Location (uri, dsym.range);
446             this.containerName = dsym.parent_name;
447         }
448     }
449
450     [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
451     public enum SymbolKind {
452         File = 1,
453         Module = 2,
454         Namespace = 3,
455         Package = 4,
456         Class = 5,
457         Method = 6,
458         Property = 7,
459         Field = 8,
460         Constructor = 9,
461         Enum = 10,
462         Interface = 11,
463         Function = 12,
464         Variable = 13,
465         Constant = 14,
466         String = 15,
467         Number = 16,
468         Boolean = 17,
469         Array = 18,
470         Object = 19,
471         Key = 20,
472         Null = 21,
473         EnumMember = 22,
474         Struct = 23,
475         Event = 24,
476         Operator = 25,
477         TypeParameter = 26
478     }
479
480         public class CompletionList : Object, Json.Serializable {
481         public bool isIncomplete { get; set; }
482         public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
483
484         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
485             base.set_property (pspec.get_name (), value);
486         }
487
488         public new Value Json.Serializable.get_property (ParamSpec pspec) {
489             Value val = Value(pspec.value_type);
490             base.get_property (pspec.get_name (), ref val);
491             return val;
492         }
493
494         public unowned ParamSpec? find_property (string name) {
495             return this.get_class ().find_property (name);
496         }
497
498         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
499             if (property_name != "items")
500                 return default_serialize_property (property_name, value, pspec);
501             var node = new Json.Node (Json.NodeType.ARRAY);
502             node.init_array (new Json.Array ());
503             var array = node.get_array ();
504             foreach (var child in items)
505                 array.add_element (Json.gobject_serialize (child));
506             return node;
507         }
508
509         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
510             error ("deserialization not supported");
511         }
512     }
513
514     [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
515     public enum CompletionTriggerKind {
516         /**
517              * Completion was triggered by typing an identifier (24x7 code
518              * complete), manual invocation (e.g Ctrl+Space) or via API.
519              */
520         Invoked = 1,
521
522         /**
523              * Completion was triggered by a trigger character specified by
524              * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
525              */
526         TriggerCharacter = 2,
527
528         /**
529              * Completion was re-triggered as the current completion list is incomplete.
530              */
531         TriggerForIncompleteCompletions = 3
532     }
533
534     public class CompletionContext : Object {
535         public CompletionTriggerKind triggerKind { get; set;}
536         public string? triggerCharacter { get; set; }
537     }
538
539     public class CompletionParams : TextDocumentPositionParams {
540         /**
541          * The completion context. This is only available if the client specifies
542          * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
543          */
544         public CompletionContext? context { get; set; }
545     }
546
547     public enum CompletionItemTag {
548         // Render a completion as obsolete, usually using a strike-out.
549         Deprecated = 1,
550     }
551
552     [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
553     public enum InsertTextFormat {
554         /**
555          * The primary text to be inserted is treated as a plain string.
556          */
557         PlainText = 1,
558
559         /**
560          * The primary text to be inserted is treated as a snippet.
561          *
562          * A snippet can define tab stops and placeholders with `$1`, `$2`
563          * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
564          * the end of the snippet. Placeholders with equal identifiers are linked,
565          * that is typing in one will update others too.
566          */
567         Snippet = 2,
568     }
569
570     public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
571         public string label { get; set; }
572         public CompletionItemKind kind { get; set; }
573         public string detail { get; set; }
574         public MarkupContent? documentation { get; set; }
575         public bool deprecated { get; set; }
576         public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
577         public string? insertText { get; set; }
578         public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
579         private uint _hash;
580
581         private CompletionItem () {}
582
583         public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
584             this.label = keyword;
585             this.kind = CompletionItemKind.Keyword;
586             this.insertText = insert_text;
587             if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
588                 this.insertTextFormat = InsertTextFormat.Snippet;
589             if (documentation != null)
590                 this.documentation = new MarkupContent.from_plaintext (documentation);
591             this._hash = @"$label $kind".hash ();
592         }
593
594         /**
595          * A completion suggestion from an existing Vala symbol.
596          * 
597          * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
598          * @param sym the symbol itself
599          * @param scope the scope to display this in
600          * @param kind the kind of completion to display
601          * @param documentation the documentation to display
602          * @param label_override if non-null, override the displayed symbol name with this
603          */
604          /*
605         public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
606             CompletionItemKind kind,
607             Vls.DocComment? documentation, string? label_override = null) {
608             this.label = label_override ?? sym.name;
609             this.kind = kind;
610             this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
611             this._hash = @"$label $kind".hash ();
612
613             if (documentation != null)
614                 this.documentation = new MarkupContent.from_markdown (documentation.body);
615
616             var version = sym.get_attribute ("Version");
617             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
618                 this.tags.add (CompletionItemTag.Deprecated);
619                 this.deprecated = true;
620             }public
621         }
622                 */
623         /**
624          * A completion suggestion from a data type and a synthetic symbol name.
625          *
626          * @param symbol_type       the data type of the symbol
627          * @param symbol_name       the name of the synthetic symbol
628          * @param scope             the scope that this completion item is displayed in, or null
629          * @param kind              the type of completion to display
630          * @param documentation     the documentation for this symbol, or null
631          */
632          /*
633         public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
634                                                      CompletionItemKind kind, Vls.DocComment? documentation) {
635             this.label = symbol_name;
636             this.kind = kind;
637             this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
638             this._hash = @"$label $kind".hash ();
639
640             if (documentation != null)
641                 this.documentation = new MarkupContent.from_markdown (documentation.body);
642         }
643         */
644                 /*
645         public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym, 
646                                                          string label, CompletionItemKind kind,
647                                                          string insert_text,
648                                                          Vls.DocComment? documentation) {
649             this.label = label;
650             this.kind = kind;
651             this.insertText = insert_text;
652             if (insert_text.contains ("$0") || insert_text.contains ("${0"))
653                 this.insertTextFormat = InsertTextFormat.Snippet;
654             this._hash = @"$label $kind".hash ();
655             if (documentation != null)
656                 this.documentation = new MarkupContent.from_markdown (documentation.body);
657         }
658         */
659
660         public uint hash () {
661             return this._hash;
662         }
663
664         public bool equal_to (CompletionItem other) {
665             return other.label == this.label && other.kind == this.kind;
666         }
667
668         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
669             base.set_property (pspec.get_name (), value);
670         }
671
672         public new Value Json.Serializable.get_property (ParamSpec pspec) {
673             Value val = Value(pspec.value_type);
674             base.get_property (pspec.get_name (), ref val);
675             return val;
676         }
677
678         public unowned ParamSpec? find_property (string name) {
679             return this.get_class ().find_property (name);
680         }
681
682         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
683             if (property_name != "tags")
684                 return default_serialize_property (property_name, value, pspec);
685
686             var node = new Json.Node (Json.NodeType.ARRAY);
687             node.init_array (new Json.Array ());
688             var array = node.get_array ();
689             foreach (var tag in this.tags) {
690                 array.add_int_element (tag);
691             }
692
693             return node;
694         }
695         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
696         {
697                 if (property_name != "tags") {
698                 return default_deserialize_property (property_name, out value, pspec, property_node);
699             }
700             value = GLib.Value (typeof(Gee.ArrayList));
701             if (property_node.get_node_type () != Json.NodeType.ARRAY) {
702                 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
703                 return false;
704             }
705
706             var arguments = new Gee.ArrayList<CompletionItemTag>();
707
708             property_node.get_array ().foreach_element ((array, index, element) => {
709                 try {
710                     arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
711                 } catch (Error e) {
712                     warning ("argument %u to command could not be deserialized: %s", index, e.message);
713                 }
714             });
715
716             value.set_object (arguments);
717             return true;
718        }
719     }
720
721     public class MarkupContent : Object {
722         public string kind { get; set; }
723         public string value { get; set; }
724
725         private MarkupContent () {}
726
727         /**
728          * Create a MarkupContent with plain text.
729          */
730         public MarkupContent.from_plaintext (string doc) {
731             this.kind = "plaintext";
732             this.value = doc;
733         }
734
735         /**
736          * Create a MarkupContent with markdown text.
737          */
738         public MarkupContent.from_markdown (string doc) {
739             this.kind = "markdown";
740             this.value = doc;
741         }
742     }
743     
744     [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
745     public enum CompletionItemKind {
746         Text = 1,
747         Method = 2,
748         Function = 3,
749         Constructor = 4,
750         Field = 5,
751         Variable = 6,
752         Class = 7,
753         Interface = 8,
754         Module = 9,
755         Property = 10,
756         Unit = 11,
757         Value = 12,
758         Enum = 13,
759         Keyword = 14,
760         Snippet = 15,
761         Color = 16,
762         File = 17,
763         Reference = 18,
764         Folder = 19,
765         EnumMember = 20,
766         Constant = 21,
767         Struct = 22,
768         Event = 23,
769         Operator = 24,
770         TypeParameter = 25
771     }
772     
773     /**
774      * Capabilities of the client/editor for `textDocument/documentSymbol`
775      */
776     public class DocumentSymbolCapabilities : Object {
777         public bool hierarchicalDocumentSymbolSupport { get; set; }
778     }
779
780     /**
781      * Capabilities of the client/editor for `textDocument/rename`
782      */
783     public class RenameClientCapabilities : Object {
784         public bool prepareSupport { get; set; }
785     }
786
787     /**
788      * Capabilities of the client/editor pertaining to language features.
789      */
790     public class TextDocumentClientCapabilities : Object {
791         public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
792         public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
793     }
794
795     /**
796      * Capabilities of the client/editor.
797      */
798     public class ClientCapabilities : Object {
799         public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
800     }
801
802     public class InitializeParams : Object {
803         public int processId { get; set; }
804         public string? rootPath { get; set; }
805         public string? rootUri { get; set; }
806         public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
807     }
808
809     public class SignatureInformation : Object, Json.Serializable {
810         public string label { get; set; }
811         public MarkupContent documentation { get; set; }
812
813         public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
814
815         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
816             base.set_property (pspec.get_name (), value);
817         }
818
819         public new Value Json.Serializable.get_property (ParamSpec pspec) {
820             Value val = Value(pspec.value_type);
821             base.get_property (pspec.get_name (), ref val);
822             return val;
823         }
824
825         public unowned ParamSpec? find_property (string name) {
826             return this.get_class ().find_property (name);
827         }
828
829         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
830             if (property_name != "parameters")
831                 return default_serialize_property (property_name, value, pspec);
832             var node = new Json.Node (Json.NodeType.ARRAY);
833             node.init_array (new Json.Array ());
834             var array = node.get_array ();
835             foreach (var child in parameters)
836                 array.add_element (Json.gobject_serialize (child));
837             return node;
838         }
839
840         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
841             error ("deserialization not supported");
842         }
843     }
844
845     public class SignatureHelp : Object, Json.Serializable {
846         public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
847         public int activeSignature { get; set; }
848         public int activeParameter { get; set; }
849
850         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
851             if (property_name != "signatures")
852                 return default_serialize_property (property_name, value, pspec);
853
854             var node = new Json.Node (Json.NodeType.ARRAY);
855             node.init_array (new Json.Array ());
856             var array = node.get_array ();
857             foreach (var child in signatures)
858                 array.add_element (Json.gobject_serialize (child));
859             return node;
860         }
861
862         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
863             error ("deserialization not supported");
864         }
865     }
866
867     public class ParameterInformation : Object {
868         public string label { get; set; }
869         public MarkupContent documentation { get; set; }
870     }
871
872    public  class MarkedString : Object {
873                 public MarkedString(string language, string value) 
874                 {
875                         this.language = language;
876                         this.value = value;
877                         GLib.debug("new marked string %s : %s", language, value);
878                 }
879         public string language { get; set; }
880         public string value { get; set; }
881     }
882
883     public class Hover : Object, Json.Serializable {
884         public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
885         public Range range { get; set; }
886
887         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
888             base.set_property (pspec.get_name (), value);
889         }
890
891         public new Value Json.Serializable.get_property (ParamSpec pspec) {
892             Value val = Value(pspec.value_type);
893             base.get_property (pspec.get_name (), ref val);
894             return val;
895         }
896
897         public unowned ParamSpec? find_property (string name) {
898             return this.get_class ().find_property (name);
899         }
900
901         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
902             if (property_name != "contents")
903                 return default_serialize_property (property_name, value, pspec);
904             var node = new Json.Node (Json.NodeType.ARRAY);
905             node.init_array (new Json.Array ());
906             var array = node.get_array ();
907             foreach (var child in contents) {
908                 if (child.language != null)
909                     array.add_element (Json.gobject_serialize (child));
910                 else
911                     array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
912             }
913             return node;
914         }
915
916         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
917         {
918             if (property_name == "contents") {
919                 value = GLib.Value (typeof(Gee.ArrayList));
920                         if (property_node.get_node_type () != Json.NodeType.ARRAY) {
921                             warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
922                             return false;
923                         }
924                                 var contents = new Gee.ArrayList<MarkedString>();
925
926                         property_node.get_array ().foreach_element ((array, index, element) => {
927                                 try {
928                                                 var add = new MarkedString(
929                                                         array.get_object_element(index).get_string_member("language"),
930                                                         array.get_object_element(index).get_string_member("value")
931                                                 );
932                              
933                                 contents.add ( add );
934                             } catch (Error e) {
935                                 warning ("argument %u to command could not be deserialized: %s", index, e.message);
936                             }
937                         });
938                 value.set_object (contents);
939                         return true;
940             } 
941             
942             return default_deserialize_property (property_name, out value, pspec, property_node);
943         }
944     }
945
946     /**
947      * A textual edit applicable to a text document.
948      */
949     public class TextEdit : Object {
950         /**
951          * The range of the text document to be manipulated. To insert
952          * text into a document create a range where ``start === end``.
953          */
954         public Range range { get; set; }
955
956         /**
957          * The string to be inserted. For delete operations use an
958          * empty string.
959          */
960         public string newText { get; set; }
961
962         public TextEdit (Range range, string new_text = "") {
963             this.range = range;
964             this.newText = new_text;
965         }
966     }
967
968     /** 
969      * Describes textual changes on a single text document. The text document is
970      * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
971      * check the text document version before an edit is applied. A
972      * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
973      * applied move the document to version ``Si+1``. So the creator of a
974      * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
975      * of ordering. However the edits must be non overlapping.
976      */
977     public class TextDocumentEdit : Object, Json.Serializable {
978         /**
979          * The text document to change.
980          */
981         public VersionedTextDocumentIdentifier textDocument { get; set; }
982
983         /**
984          * The edits to be applied.
985          */
986         public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
987
988         public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
989             this.textDocument = text_document;
990         }
991
992         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
993             if (property_name != "edits")
994                 return default_serialize_property (property_name, value, pspec);
995             
996             var node = new Json.Node (Json.NodeType.ARRAY);
997             node.init_array (new Json.Array ());
998             var array = node.get_array ();
999             foreach (var text_edit in edits) {
1000                 array.add_element (Json.gobject_serialize (text_edit));
1001             }
1002             return node;
1003         }
1004
1005         public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1006             error ("deserialization not supported");
1007         }
1008     }
1009
1010     public abstract class CommandLike : Object, Json.Serializable {
1011         /**
1012          * The identifier of the actual command handler.
1013          */
1014         public string command { get; set; }
1015
1016         /**
1017          * Arguments that the command handler should be invoked with.
1018          */
1019         public Array<Variant>? arguments { get; set; }
1020
1021         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1022             if (property_name != "arguments" || arguments == null)
1023                 return default_serialize_property (property_name, value, pspec);
1024
1025             var array = new Json.Array ();
1026             for (int i = 0; i < arguments.length; i++)
1027                 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1028
1029             var node = new Json.Node (Json.NodeType.ARRAY);
1030             node.set_array (array);
1031             return node;
1032         }
1033
1034         public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) 
1035         {
1036             if (property_name == "arguments") {
1037                 value = GLib.Value (typeof(Array));
1038                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1039                     warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1040                     return false;
1041                 }
1042
1043                 var arguments = new Array<Variant> ();
1044
1045                 property_node.get_array ().foreach_element ((array, index, element) => {
1046                     try {
1047                         arguments.append_val (Json.gvariant_deserialize (element, null));
1048                     } catch (Error e) {
1049                         warning ("argument %u to command could not be deserialized: %s", index, e.message);
1050                     }
1051                 });
1052
1053                 value.set_boxed (arguments);
1054                 return true;
1055             } else if (property_name == "command") {
1056                 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1057                 if (property_node.get_value_type () != typeof (string)) {
1058                     value = "";
1059                     warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1060                     return false;
1061                 }
1062
1063                 value = property_node.get_string ();
1064                 return true;
1065             } else {
1066                 return default_deserialize_property (property_name, out value, pspec, property_node);
1067             }
1068         }
1069     }
1070
1071     public class ExecuteCommandParams : CommandLike {
1072     }
1073
1074     /**
1075      * Represents a reference to a command. Provides a title which will be used
1076      * to represent a command in the UI. Commands are identified by a string
1077      * identifier. The recommended way to handle commands is to implement their
1078      * execution on the server side if the client and server provides the
1079      * corresponding capabilities. Alternatively the tool extension code could
1080      * handle the command. The protocol currently doesn’t specify a set of
1081      * well-known commands.
1082      */
1083     public class Command : CommandLike {
1084         /**
1085          * The title of the command, like `save`.
1086          */
1087         public string title { get; set; }
1088     }
1089
1090     /**
1091      * A code lens represents a command that should be shown along with
1092      * source text, like the number of references, a way to run tests, etc.
1093      *
1094      * A code lens is _unresolved_ when no command is associated to it. For
1095      * performance reasons the creation of a code lens and resolving should be done
1096      * in two stages.
1097      */
1098     public class CodeLens : Object {
1099         /**
1100          * The range in which this code lens is valid. Should only span a single
1101          * line.
1102          */
1103         public Range range { get; set; }
1104
1105         /**
1106          * The command this code lens represents.
1107          */
1108         public Command? command { get; set; }
1109     }
1110     
1111     public class DocumentRangeFormattingParams : Object {
1112         public TextDocumentIdentifier textDocument { get; set; }
1113         public Range? range { get; set; }
1114         public FormattingOptions options { get; set; }
1115     }
1116
1117     public class FormattingOptions : Object {
1118         public uint tabSize { get; set; }
1119         public bool insertSpaces { get; set; }
1120         public bool trimTrailingWhitespace { get; set; }
1121         public bool insertFinalNewline { get; set; }
1122         public bool trimFinalNewlines { get; set; }
1123     }
1124
1125     public class CodeActionParams : Object {
1126         public TextDocumentIdentifier textDocument { get; set; }
1127         public Range range { get; set; }
1128         public CodeActionContext context { get; set; }
1129     }
1130
1131
1132     public class CodeActionContext : Object, Json.Serializable {
1133         public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1134         public string[]? only { get; set; }
1135 /*
1136         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1137             if (property_name != "diagnostics")
1138                 return default_deserialize_property (property_name, out value, pspec, property_node);
1139             var diags = new Gee.ArrayList<Diagnostic> ();
1140             property_node.get_array ().foreach_element ((array, index, element) => {
1141                 try {
1142                     diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1143                 } catch (Error e) {
1144                     warning ("argument %u could not be deserialized: %s", index, e.message);
1145                 }
1146             });
1147             value = diags;
1148             return true;
1149         }
1150         */
1151     }
1152
1153
1154         public class Diagnostics : Object, Json.Serializable 
1155         {
1156                 public Diagnostics()
1157                 {
1158                         this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1159                                 return a.equals(b);
1160                         });
1161                 }
1162                 
1163                 public string uri { get; set; }
1164
1165                 public int version  { get; set; default = 0; }
1166         public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1167                  
1168                 public string filename { 
1169                         owned get {
1170                                 return File.new_for_uri (this.uri).get_path();
1171                         }
1172                         private set {}
1173                 }
1174                 
1175                 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1176                         if (property_name == "diagnostics") {
1177                 val = GLib.Value (typeof(Gee.ArrayList));
1178                                 var diags =  new Gee.ArrayList<Diagnostic> ((a,b) => {
1179                                         return a.equals(b);
1180                                 });
1181                                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1182                                         val.set_object(diags);
1183                                         warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1184                                         return false;
1185                                 }
1186
1187                                 
1188
1189                                 property_node.get_array ().foreach_element ((array, index, element) => {
1190                                          
1191                                                 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1192                                          
1193                                                 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1194                                          
1195                                 });
1196                                 val.set_object(diags);
1197                                  
1198                                 return true;
1199                         }   
1200                          
1201                         return default_deserialize_property (property_name, out val, pspec, property_node);
1202                          
1203                 }
1204
1205                 
1206         }
1207
1208
1209    public  class CodeAction : Object, Json.Serializable {
1210         public string title { get; set; }
1211         public string? kind { get; set; }
1212         public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1213         public bool isPreferred { get; set; }
1214         public WorkspaceEdit? edit { get; set; }
1215         public Command? command { get; set; }
1216         public Object? data { get; set; }
1217
1218         protected void add_diagnostic (Diagnostic diag) {
1219             if (diagnostics == null)
1220                 diagnostics = new Gee.ArrayList<Diagnostic> ();
1221             diagnostics.add (diag);
1222         }
1223
1224         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1225             if (property_name != "diagnostics")
1226                 return default_serialize_property (property_name, value, pspec);
1227
1228             var array = new Json.Array ();
1229             if (diagnostics != null)
1230                 foreach (var text_edit in diagnostics)
1231                     array.add_element (Json.gobject_serialize (text_edit));
1232             return new Json.Node.alloc ().init_array (array);
1233         }
1234     }
1235
1236     public class WorkspaceEdit : Object, Json.Serializable {
1237         public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1238
1239         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1240             if (property_name != "documentChanges")
1241                 return default_serialize_property (property_name, value, pspec);
1242
1243             var node = new Json.Node (Json.NodeType.ARRAY);
1244             node.init_array (new Json.Array ());
1245             if (documentChanges != null) {
1246                 var array = node.get_array ();
1247                 foreach (var text_edit in documentChanges) {
1248                     array.add_element (Json.gobject_serialize (text_edit));
1249                 }
1250             }
1251             return node;
1252         }
1253     }
1254
1255     [Flags]
1256     public enum SymbolTags {
1257         NONE,
1258         DEPRECATED
1259     }
1260
1261     public class CallHierarchyItem : Object, Json.Serializable {
1262         public string name { get; set; }
1263         public SymbolKind kind { get; set; }
1264         public SymbolTags tags { get; set; }
1265         public string? detail { get; set; }
1266         public string uri { get; set; }
1267         public Range range { get; set; }
1268         public Range selectionRange { get; set; }
1269
1270         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1271             if (property_name != "tags")
1272                 return default_serialize_property (property_name, value, pspec);
1273             var array = new Json.Array ();
1274             if (SymbolTags.DEPRECATED in tags)
1275                 array.add_int_element (SymbolTags.DEPRECATED);
1276             return new Json.Node.alloc ().init_array (array);
1277         }
1278 /*
1279         public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1280             this.name = symbol.get_full_name ();
1281             if (symbol is Vala.Method) {
1282                 if (symbol.parent_symbol is Vala.Namespace)
1283                     this.kind = SymbolKind.Function;
1284                 else
1285                     this.kind = SymbolKind.Method;
1286             } else if (symbol is Vala.Signal) {
1287                 this.kind = SymbolKind.Event;
1288             } else if (symbol is Vala.Constructor) {
1289                 this.kind = SymbolKind.Constructor;
1290             } else {
1291                 this.kind = SymbolKind.Method;
1292             }
1293             var version = symbol.get_attribute ("Version");
1294             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1295                 this.tags |= SymbolTags.DEPRECATED;
1296             }
1297             this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1298             this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1299             this.range = new Range.from_sourceref (symbol.source_reference);
1300             if (symbol.comment != null)
1301                 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1302             if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1303                 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1304             this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1305         }
1306         */
1307     }
1308
1309     public class CallHierarchyIncomingCall : Json.Serializable, Object {
1310         /**
1311          * The method that calls the query method.
1312          */
1313         public CallHierarchyItem from { get; set; }
1314
1315         /**
1316          * The ranges at which the query method is called by `from`.
1317          */
1318         public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1319
1320         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1321             if (property_name == "from")
1322                 return default_serialize_property (property_name, value, pspec);
1323             var array = new Json.Array ();
1324             foreach (var range in fromRanges)
1325                 array.add_element (Json.gobject_serialize (range));
1326             return new Json.Node.alloc ().init_array (array);
1327         }
1328     }
1329
1330     public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1331         /**
1332          * The method that the query method calls.
1333          */
1334         public CallHierarchyItem to { get; set; }
1335
1336         /**
1337          * The ranges at which the method is called by the query method.
1338          */
1339         public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1340
1341         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1342             if (property_name == "to")
1343                 return default_serialize_property (property_name, value, pspec);
1344             var array = new Json.Array ();
1345             foreach (var range in fromRanges)
1346                 array.add_element (Json.gobject_serialize (range));
1347             return new Json.Node.alloc ().init_array (array);
1348         }
1349     }
1350
1351     public class InlayHintParams : Json.Serializable, Object {
1352         public TextDocumentIdentifier textDocument { get; set; }
1353         public Range range { get; set; }
1354     }
1355
1356     public enum InlayHintKind {
1357         UNSET,
1358         TYPE,
1359         PARAMETER
1360     }
1361
1362     public class InlayHint : Object {
1363         public Position position { get; set; }
1364         public string label { get; set; }
1365         public InlayHintKind kind { get; set; }
1366         public string? tooltip { get; set; }
1367         public bool paddingLeft { get; set; }
1368         public bool paddingRight { get; set; }
1369     }
1370
1371    public  class TypeHierarchyItem : Object, Json.Serializable {
1372         /**
1373          * The name of this item
1374          */
1375         public string name { get; set; }
1376
1377         /**
1378          * The kind of this item
1379          */
1380         public SymbolKind kind { get; set; }
1381
1382         /**
1383          * Tags for this item
1384          */
1385         public SymbolTags tags { get; set; }
1386
1387         /**
1388          * More detail for this item, e.g. the signature of a function.
1389          */
1390         public string? detail { get; set; }
1391
1392         /**
1393          * The resource identifier of this item.
1394          */
1395         public string uri { get; set; }
1396
1397         /**
1398          * The range enclosing this symbol not including leading/trailing
1399          * whitespace, but everything else, e.g. comments and code.
1400          */
1401         public Range range { get; set; }
1402
1403         /**
1404          * The range that should be selected and revealed when this symbol
1405          * is being picked, e.g. the name of a function. Must be contained
1406          * by {@link TypeHierarchyItem.range}
1407          */
1408         public Range selectionRange { get; set; }
1409
1410         private TypeHierarchyItem () {}
1411 /*
1412         public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1413             this.name = symbol.get_full_name ();
1414             if (symbol is Vala.Class)
1415                 this.kind = SymbolKind.Class;
1416             else if (symbol is Vala.Delegate)
1417                 this.kind = SymbolKind.Interface;
1418             else if (symbol is Vala.Enum)
1419                 this.kind = SymbolKind.Enum;
1420             else if (symbol is Vala.ErrorCode)
1421                 this.kind = SymbolKind.EnumMember;
1422             else if (symbol is Vala.ErrorDomain)
1423                 this.kind = SymbolKind.Enum;
1424             else if (symbol is Vala.Interface)
1425                 this.kind = SymbolKind.Interface;
1426             else if (symbol is Vala.Struct)
1427                 this.kind = SymbolKind.Struct;
1428             else if (symbol is Vala.TypeParameter)
1429                 this.kind = SymbolKind.TypeParameter;
1430             else {
1431                 this.kind = SymbolKind.Module;
1432                 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1433             }
1434
1435             var version = symbol.get_attribute ("Version");
1436             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1437                 this.tags |= SymbolTags.DEPRECATED;
1438             }
1439             this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1440             this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1441             this.range = new Range.from_sourceref (symbol.source_reference);
1442             this.selectionRange = this.range;
1443
1444             // widen range to include all members
1445             if (symbol is Vala.ObjectTypeSymbol) {
1446                 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1447                     if (member.source_reference != null)
1448                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1449                 }
1450             } else if (symbol is Vala.Enum) {
1451                 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1452                     if (member.source_reference != null)
1453                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1454                 }
1455                 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1456                     if (method.source_reference != null)
1457                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1458                 }
1459             } else if (symbol is Vala.ErrorDomain) {
1460                 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1461                     if (member.source_reference != null)
1462                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1463                 }
1464                 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1465                     if (method.source_reference != null)
1466                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1467                 }
1468             } else if (symbol is Vala.Struct) {
1469                 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1470                     if (field.source_reference != null)
1471                         this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1472                 }
1473                 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1474                     if (method.source_reference != null)
1475                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1476                 }
1477             }
1478         }
1479         */
1480     }
1481 }