815438b98a6ed1b48500409b7bda30f44a564d68
[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
344        public Range range { get; set; } 
345         public Range selectionRange { get; set; }
346         public GLib.ListStore children { get; private set; default = new GLib.ListStore(typeof(DocumentSymbol)); }
347         public string? parent_name;
348
349         private DocumentSymbol () {}
350
351         /**
352          * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
353          * @param sym the symbol
354          */
355          /*
356         public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
357             this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
358             this._initial_range = new Range.from_sourceref (sym.source_reference);
359             if (sym is Vala.Subroutine) {
360                 var sub = (Vala.Subroutine) sym;
361                 var body_sref = sub.body != null ? sub.body.source_reference : null;
362                 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
363                 //         body_sref != null ? body_sref.to_string () : null);
364                 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
365                                 val = GLib.Value (typeof(Gee.ArrayList));                          body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
366                     this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
367                 }
368             }
369             this.name = sym.name;
370             this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
371             this.kind = kind;
372             this.selectionRange = new Range.from_sourceref (sym.source_reference);
373             this.deprecated = sym.version.deprecated;
374         }
375         */
376         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
377             base.set_property (pspec.get_name (), value);
378         }
379
380         public new Value Json.Serializable.get_property (ParamSpec pspec) {
381             Value val = Value (pspec.value_type);
382             base.get_property (pspec.get_name (), ref val);
383             return val;
384         }
385
386         public unowned ParamSpec? find_property (string name) {
387             return this.get_class ().find_property (name);
388         }
389
390         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
391            // if (property_name != "children")
392                 return default_serialize_property (property_name, value, pspec);
393             /*var node = new Json.Node (Json.NodeType.ARRAY);
394             node.init_array (new Json.Array ());
395             var array = node.get_array ();
396             foreach (var child in children)
397                 array.add_element (Json.gobject_serialize (child));
398             return node;
399             */
400         }
401
402         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
403             {
404                 GLib.debug("deserialise property %s" , property_name);
405                 if (property_name != "children") {
406                     return default_deserialize_property (property_name, out value, pspec, property_node);
407                 }
408             value = GLib.Value (typeof(GLib.ListStore));
409                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
410                     GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
411                     return false;
412                 }
413                         GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
414                 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
415
416                 property_node.get_array ().foreach_element ((array, index, element) => {
417                     
418                         var add= Json.gobject_deserialize ( typeof (DocumentSymbol),  array.get_element(index)) as DocumentSymbol;
419                                 arguments.append( add);
420
421                    
422                 });
423
424                 value.set_object (arguments);
425                 return true;
426            }
427     }
428
429     public class SymbolInformation : Object {
430         public string name { get; set; }
431         public SymbolKind kind { get; set; }
432         public Location location { get; set; }
433         public string? containerName { get; set; }
434
435         public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
436             this.name = dsym.name;
437             this.kind = dsym.kind;
438           //  this.location = new Location (uri, dsym.range);
439             this.containerName = dsym.parent_name;
440         }
441     }
442
443     [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
444     public enum SymbolKind {
445         File = 1,
446         Module = 2,
447         Namespace = 3,
448         Package = 4,
449         Class = 5,
450         Method = 6,
451         Property = 7,
452         Field = 8,
453         Constructor = 9,
454         Enum = 10,
455         Interface = 11,
456         Function = 12,
457         Variable = 13,
458         Constant = 14,
459         String = 15,
460         Number = 16,
461         Boolean = 17,
462         Array = 18,
463         Object = 19,
464         Key = 20,
465         Null = 21,
466         EnumMember = 22,
467         Struct = 23,
468         Event = 24,
469         Operator = 25,
470         TypeParameter = 26
471     }
472
473         public class CompletionList : Object, Json.Serializable {
474         public bool isIncomplete { get; set; }
475         public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
476
477         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
478             base.set_property (pspec.get_name (), value);
479         }
480
481         public new Value Json.Serializable.get_property (ParamSpec pspec) {
482             Value val = Value(pspec.value_type);
483             base.get_property (pspec.get_name (), ref val);
484             return val;
485         }
486
487         public unowned ParamSpec? find_property (string name) {
488             return this.get_class ().find_property (name);
489         }
490
491         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
492             if (property_name != "items")
493                 return default_serialize_property (property_name, value, pspec);
494             var node = new Json.Node (Json.NodeType.ARRAY);
495             node.init_array (new Json.Array ());
496             var array = node.get_array ();
497             foreach (var child in items)
498                 array.add_element (Json.gobject_serialize (child));
499             return node;
500         }
501
502         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
503             error ("deserialization not supported");
504         }
505     }
506
507     [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
508     public enum CompletionTriggerKind {
509         /**
510              * Completion was triggered by typing an identifier (24x7 code
511              * complete), manual invocation (e.g Ctrl+Space) or via API.
512              */
513         Invoked = 1,
514
515         /**
516              * Completion was triggered by a trigger character specified by
517              * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
518              */
519         TriggerCharacter = 2,
520
521         /**
522              * Completion was re-triggered as the current completion list is incomplete.
523              */
524         TriggerForIncompleteCompletions = 3
525     }
526
527     public class CompletionContext : Object {
528         public CompletionTriggerKind triggerKind { get; set;}
529         public string? triggerCharacter { get; set; }
530     }
531
532     public class CompletionParams : TextDocumentPositionParams {
533         /**
534          * The completion context. This is only available if the client specifies
535          * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
536          */
537         public CompletionContext? context { get; set; }
538     }
539
540     public enum CompletionItemTag {
541         // Render a completion as obsolete, usually using a strike-out.
542         Deprecated = 1,
543     }
544
545     [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
546     public enum InsertTextFormat {
547         /**
548          * The primary text to be inserted is treated as a plain string.
549          */
550         PlainText = 1,
551
552         /**
553          * The primary text to be inserted is treated as a snippet.
554          *
555          * A snippet can define tab stops and placeholders with `$1`, `$2`
556          * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
557          * the end of the snippet. Placeholders with equal identifiers are linked,
558          * that is typing in one will update others too.
559          */
560         Snippet = 2,
561     }
562
563     public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
564         public string label { get; set; }
565         public CompletionItemKind kind { get; set; }
566         public string detail { get; set; }
567         public MarkupContent? documentation { get; set; }
568         public bool deprecated { get; set; }
569         public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
570         public string? insertText { get; set; }
571         public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
572         private uint _hash;
573
574         private CompletionItem () {}
575
576         public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
577             this.label = keyword;
578             this.kind = CompletionItemKind.Keyword;
579             this.insertText = insert_text;
580             if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
581                 this.insertTextFormat = InsertTextFormat.Snippet;
582             if (documentation != null)
583                 this.documentation = new MarkupContent.from_plaintext (documentation);
584             this._hash = @"$label $kind".hash ();
585         }
586
587         /**
588          * A completion suggestion from an existing Vala symbol.
589          * 
590          * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
591          * @param sym the symbol itself
592          * @param scope the scope to display this in
593          * @param kind the kind of completion to display
594          * @param documentation the documentation to display
595          * @param label_override if non-null, override the displayed symbol name with this
596          */
597          /*
598         public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
599             CompletionItemKind kind,
600             Vls.DocComment? documentation, string? label_override = null) {
601             this.label = label_override ?? sym.name;
602             this.kind = kind;
603             this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
604             this._hash = @"$label $kind".hash ();
605
606             if (documentation != null)
607                 this.documentation = new MarkupContent.from_markdown (documentation.body);
608
609             var version = sym.get_attribute ("Version");
610             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
611                 this.tags.add (CompletionItemTag.Deprecated);
612                 this.deprecated = true;
613             }public
614         }
615                 */
616         /**
617          * A completion suggestion from a data type and a synthetic symbol name.
618          *
619          * @param symbol_type       the data type of the symbol
620          * @param symbol_name       the name of the synthetic symbol
621          * @param scope             the scope that this completion item is displayed in, or null
622          * @param kind              the type of completion to display
623          * @param documentation     the documentation for this symbol, or null
624          */
625          /*
626         public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
627                                                      CompletionItemKind kind, Vls.DocComment? documentation) {
628             this.label = symbol_name;
629             this.kind = kind;
630             this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
631             this._hash = @"$label $kind".hash ();
632
633             if (documentation != null)
634                 this.documentation = new MarkupContent.from_markdown (documentation.body);
635         }
636         */
637                 /*
638         public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym, 
639                                                          string label, CompletionItemKind kind,
640                                                          string insert_text,
641                                                          Vls.DocComment? documentation) {
642             this.label = label;
643             this.kind = kind;
644             this.insertText = insert_text;
645             if (insert_text.contains ("$0") || insert_text.contains ("${0"))
646                 this.insertTextFormat = InsertTextFormat.Snippet;
647             this._hash = @"$label $kind".hash ();
648             if (documentation != null)
649                 this.documentation = new MarkupContent.from_markdown (documentation.body);
650         }
651         */
652
653         public uint hash () {
654             return this._hash;
655         }
656
657         public bool equal_to (CompletionItem other) {
658             return other.label == this.label && other.kind == this.kind;
659         }
660
661         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
662             base.set_property (pspec.get_name (), value);
663         }
664
665         public new Value Json.Serializable.get_property (ParamSpec pspec) {
666             Value val = Value(pspec.value_type);
667             base.get_property (pspec.get_name (), ref val);
668             return val;
669         }
670
671         public unowned ParamSpec? find_property (string name) {
672             return this.get_class ().find_property (name);
673         }
674
675         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
676             if (property_name != "tags")
677                 return default_serialize_property (property_name, value, pspec);
678
679             var node = new Json.Node (Json.NodeType.ARRAY);
680             node.init_array (new Json.Array ());
681             var array = node.get_array ();
682             foreach (var tag in this.tags) {
683                 array.add_int_element (tag);
684             }
685
686             return node;
687         }
688         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
689         {
690                 if (property_name != "tags") {
691                 return default_deserialize_property (property_name, out value, pspec, property_node);
692             }
693             value = GLib.Value (typeof(Gee.ArrayList));
694             if (property_node.get_node_type () != Json.NodeType.ARRAY) {
695                 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
696                 return false;
697             }
698
699             var arguments = new Gee.ArrayList<CompletionItemTag>();
700
701             property_node.get_array ().foreach_element ((array, index, element) => {
702                 try {
703                     arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
704                 } catch (Error e) {
705                     warning ("argument %u to command could not be deserialized: %s", index, e.message);
706                 }
707             });
708
709             value.set_object (arguments);
710             return true;
711        }
712     }
713
714     public class MarkupContent : Object {
715         public string kind { get; set; }
716         public string value { get; set; }
717
718         private MarkupContent () {}
719
720         /**
721          * Create a MarkupContent with plain text.
722          */
723         public MarkupContent.from_plaintext (string doc) {
724             this.kind = "plaintext";
725             this.value = doc;
726         }
727
728         /**
729          * Create a MarkupContent with markdown text.
730          */
731         public MarkupContent.from_markdown (string doc) {
732             this.kind = "markdown";
733             this.value = doc;
734         }
735     }
736     
737     [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
738     public enum CompletionItemKind {
739         Text = 1,
740         Method = 2,
741         Function = 3,
742         Constructor = 4,
743         Field = 5,
744         Variable = 6,
745         Class = 7,
746         Interface = 8,
747         Module = 9,
748         Property = 10,
749         Unit = 11,
750         Value = 12,
751         Enum = 13,
752         Keyword = 14,
753         Snippet = 15,
754         Color = 16,
755         File = 17,
756         Reference = 18,
757         Folder = 19,
758         EnumMember = 20,
759         Constant = 21,
760         Struct = 22,
761         Event = 23,
762         Operator = 24,
763         TypeParameter = 25
764     }
765     
766     /**
767      * Capabilities of the client/editor for `textDocument/documentSymbol`
768      */
769     public class DocumentSymbolCapabilities : Object {
770         public bool hierarchicalDocumentSymbolSupport { get; set; }
771     }
772
773     /**
774      * Capabilities of the client/editor for `textDocument/rename`
775      */
776     public class RenameClientCapabilities : Object {
777         public bool prepareSupport { get; set; }
778     }
779
780     /**
781      * Capabilities of the client/editor pertaining to language features.
782      */
783     public class TextDocumentClientCapabilities : Object {
784         public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
785         public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
786     }
787
788     /**
789      * Capabilities of the client/editor.
790      */
791     public class ClientCapabilities : Object {
792         public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
793     }
794
795     public class InitializeParams : Object {
796         public int processId { get; set; }
797         public string? rootPath { get; set; }
798         public string? rootUri { get; set; }
799         public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
800     }
801
802     public class SignatureInformation : Object, Json.Serializable {
803         public string label { get; set; }
804         public MarkupContent documentation { get; set; }
805
806         public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
807
808         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
809             base.set_property (pspec.get_name (), value);
810         }
811
812         public new Value Json.Serializable.get_property (ParamSpec pspec) {
813             Value val = Value(pspec.value_type);
814             base.get_property (pspec.get_name (), ref val);
815             return val;
816         }
817
818         public unowned ParamSpec? find_property (string name) {
819             return this.get_class ().find_property (name);
820         }
821
822         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
823             if (property_name != "parameters")
824                 return default_serialize_property (property_name, value, pspec);
825             var node = new Json.Node (Json.NodeType.ARRAY);
826             node.init_array (new Json.Array ());
827             var array = node.get_array ();
828             foreach (var child in parameters)
829                 array.add_element (Json.gobject_serialize (child));
830             return node;
831         }
832
833         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
834             error ("deserialization not supported");
835         }
836     }
837
838     public class SignatureHelp : Object, Json.Serializable {
839         public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
840         public int activeSignature { get; set; }
841         public int activeParameter { get; set; }
842
843         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
844             if (property_name != "signatures")
845                 return default_serialize_property (property_name, value, pspec);
846
847             var node = new Json.Node (Json.NodeType.ARRAY);
848             node.init_array (new Json.Array ());
849             var array = node.get_array ();
850             foreach (var child in signatures)
851                 array.add_element (Json.gobject_serialize (child));
852             return node;
853         }
854
855         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
856             error ("deserialization not supported");
857         }
858     }
859
860     public class ParameterInformation : Object {
861         public string label { get; set; }
862         public MarkupContent documentation { get; set; }
863     }
864
865    public  class MarkedString : Object {
866                 public MarkedString(string language, string value) 
867                 {
868                         this.language = language;
869                         this.value = value;
870                         GLib.debug("new marked string %s : %s", language, value);
871                 }
872         public string language { get; set; }
873         public string value { get; set; }
874     }
875
876     public class Hover : Object, Json.Serializable {
877         public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
878         public Range range { get; set; }
879
880         public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
881             base.set_property (pspec.get_name (), value);
882         }
883
884         public new Value Json.Serializable.get_property (ParamSpec pspec) {
885             Value val = Value(pspec.value_type);
886             base.get_property (pspec.get_name (), ref val);
887             return val;
888         }
889
890         public unowned ParamSpec? find_property (string name) {
891             return this.get_class ().find_property (name);
892         }
893
894         public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
895             if (property_name != "contents")
896                 return default_serialize_property (property_name, value, pspec);
897             var node = new Json.Node (Json.NodeType.ARRAY);
898             node.init_array (new Json.Array ());
899             var array = node.get_array ();
900             foreach (var child in contents) {
901                 if (child.language != null)
902                     array.add_element (Json.gobject_serialize (child));
903                 else
904                     array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
905             }
906             return node;
907         }
908
909         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) 
910         {
911             if (property_name == "contents") {
912                 value = GLib.Value (typeof(Gee.ArrayList));
913                         if (property_node.get_node_type () != Json.NodeType.ARRAY) {
914                             warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
915                             return false;
916                         }
917                                 var contents = new Gee.ArrayList<MarkedString>();
918
919                         property_node.get_array ().foreach_element ((array, index, element) => {
920                                 try {
921                                                 var add = new MarkedString(
922                                                         array.get_object_element(index).get_string_member("language"),
923                                                         array.get_object_element(index).get_string_member("value")
924                                                 );
925                              
926                                 contents.add ( add );
927                             } catch (Error e) {
928                                 warning ("argument %u to command could not be deserialized: %s", index, e.message);
929                             }
930                         });
931                 value.set_object (contents);
932                         return true;
933             } 
934             
935             return default_deserialize_property (property_name, out value, pspec, property_node);
936         }
937     }
938
939     /**
940      * A textual edit applicable to a text document.
941      */
942     public class TextEdit : Object {
943         /**
944          * The range of the text document to be manipulated. To insert
945          * text into a document create a range where ``start === end``.
946          */
947         public Range range { get; set; }
948
949         /**
950          * The string to be inserted. For delete operations use an
951          * empty string.
952          */
953         public string newText { get; set; }
954
955         public TextEdit (Range range, string new_text = "") {
956             this.range = range;
957             this.newText = new_text;
958         }
959     }
960
961     /** 
962      * Describes textual changes on a single text document. The text document is
963      * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
964      * check the text document version before an edit is applied. A
965      * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
966      * applied move the document to version ``Si+1``. So the creator of a
967      * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
968      * of ordering. However the edits must be non overlapping.
969      */
970     public class TextDocumentEdit : Object, Json.Serializable {
971         /**
972          * The text document to change.
973          */
974         public VersionedTextDocumentIdentifier textDocument { get; set; }
975
976         /**
977          * The edits to be applied.
978          */
979         public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
980
981         public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
982             this.textDocument = text_document;
983         }
984
985         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
986             if (property_name != "edits")
987                 return default_serialize_property (property_name, value, pspec);
988             
989             var node = new Json.Node (Json.NodeType.ARRAY);
990             node.init_array (new Json.Array ());
991             var array = node.get_array ();
992             foreach (var text_edit in edits) {
993                 array.add_element (Json.gobject_serialize (text_edit));
994             }
995             return node;
996         }
997
998         public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
999             error ("deserialization not supported");
1000         }
1001     }
1002
1003     public abstract class CommandLike : Object, Json.Serializable {
1004         /**
1005          * The identifier of the actual command handler.
1006          */
1007         public string command { get; set; }
1008
1009         /**
1010          * Arguments that the command handler should be invoked with.
1011          */
1012         public Array<Variant>? arguments { get; set; }
1013
1014         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1015             if (property_name != "arguments" || arguments == null)
1016                 return default_serialize_property (property_name, value, pspec);
1017
1018             var array = new Json.Array ();
1019             for (int i = 0; i < arguments.length; i++)
1020                 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1021
1022             var node = new Json.Node (Json.NodeType.ARRAY);
1023             node.set_array (array);
1024             return node;
1025         }
1026
1027         public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) 
1028         {
1029             if (property_name == "arguments") {
1030                 value = GLib.Value (typeof(Array));
1031                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1032                     warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1033                     return false;
1034                 }
1035
1036                 var arguments = new Array<Variant> ();
1037
1038                 property_node.get_array ().foreach_element ((array, index, element) => {
1039                     try {
1040                         arguments.append_val (Json.gvariant_deserialize (element, null));
1041                     } catch (Error e) {
1042                         warning ("argument %u to command could not be deserialized: %s", index, e.message);
1043                     }
1044                 });
1045
1046                 value.set_boxed (arguments);
1047                 return true;
1048             } else if (property_name == "command") {
1049                 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1050                 if (property_node.get_value_type () != typeof (string)) {
1051                     value = "";
1052                     warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1053                     return false;
1054                 }
1055
1056                 value = property_node.get_string ();
1057                 return true;
1058             } else {
1059                 return default_deserialize_property (property_name, out value, pspec, property_node);
1060             }
1061         }
1062     }
1063
1064     public class ExecuteCommandParams : CommandLike {
1065     }
1066
1067     /**
1068      * Represents a reference to a command. Provides a title which will be used
1069      * to represent a command in the UI. Commands are identified by a string
1070      * identifier. The recommended way to handle commands is to implement their
1071      * execution on the server side if the client and server provides the
1072      * corresponding capabilities. Alternatively the tool extension code could
1073      * handle the command. The protocol currently doesn’t specify a set of
1074      * well-known commands.
1075      */
1076     public class Command : CommandLike {
1077         /**
1078          * The title of the command, like `save`.
1079          */
1080         public string title { get; set; }
1081     }
1082
1083     /**
1084      * A code lens represents a command that should be shown along with
1085      * source text, like the number of references, a way to run tests, etc.
1086      *
1087      * A code lens is _unresolved_ when no command is associated to it. For
1088      * performance reasons the creation of a code lens and resolving should be done
1089      * in two stages.
1090      */
1091     public class CodeLens : Object {
1092         /**
1093          * The range in which this code lens is valid. Should only span a single
1094          * line.
1095          */
1096         public Range range { get; set; }
1097
1098         /**
1099          * The command this code lens represents.
1100          */
1101         public Command? command { get; set; }
1102     }
1103     
1104     public class DocumentRangeFormattingParams : Object {
1105         public TextDocumentIdentifier textDocument { get; set; }
1106         public Range? range { get; set; }
1107         public FormattingOptions options { get; set; }
1108     }
1109
1110     public class FormattingOptions : Object {
1111         public uint tabSize { get; set; }
1112         public bool insertSpaces { get; set; }
1113         public bool trimTrailingWhitespace { get; set; }
1114         public bool insertFinalNewline { get; set; }
1115         public bool trimFinalNewlines { get; set; }
1116     }
1117
1118     public class CodeActionParams : Object {
1119         public TextDocumentIdentifier textDocument { get; set; }
1120         public Range range { get; set; }
1121         public CodeActionContext context { get; set; }
1122     }
1123
1124
1125     public class CodeActionContext : Object, Json.Serializable {
1126         public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1127         public string[]? only { get; set; }
1128 /*
1129         public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1130             if (property_name != "diagnostics")
1131                 return default_deserialize_property (property_name, out value, pspec, property_node);
1132             var diags = new Gee.ArrayList<Diagnostic> ();
1133             property_node.get_array ().foreach_element ((array, index, element) => {
1134                 try {
1135                     diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1136                 } catch (Error e) {
1137                     warning ("argument %u could not be deserialized: %s", index, e.message);
1138                 }
1139             });
1140             value = diags;
1141             return true;
1142         }
1143         */
1144     }
1145
1146
1147         public class Diagnostics : Object, Json.Serializable 
1148         {
1149                 public Diagnostics()
1150                 {
1151                         this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1152                                 return a.equals(b);
1153                         });
1154                 }
1155                 
1156                 public string uri { get; set; }
1157
1158                 public int version  { get; set; default = 0; }
1159         public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1160                  
1161                 public string filename { 
1162                         owned get {
1163                                 return File.new_for_uri (this.uri).get_path();
1164                         }
1165                         private set {}
1166                 }
1167                 
1168                 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1169                         if (property_name == "diagnostics") {
1170                 val = GLib.Value (typeof(Gee.ArrayList));
1171                                 var diags =  new Gee.ArrayList<Diagnostic> ((a,b) => {
1172                                         return a.equals(b);
1173                                 });
1174                                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1175                                         val.set_object(diags);
1176                                         warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1177                                         return false;
1178                                 }
1179
1180                                 
1181
1182                                 property_node.get_array ().foreach_element ((array, index, element) => {
1183                                          
1184                                                 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1185                                          
1186                                                 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1187                                          
1188                                 });
1189                                 val.set_object(diags);
1190                                  
1191                                 return true;
1192                         }   
1193                          
1194                         return default_deserialize_property (property_name, out val, pspec, property_node);
1195                          
1196                 }
1197
1198                 
1199         }
1200
1201
1202    public  class CodeAction : Object, Json.Serializable {
1203         public string title { get; set; }
1204         public string? kind { get; set; }
1205         public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1206         public bool isPreferred { get; set; }
1207         public WorkspaceEdit? edit { get; set; }
1208         public Command? command { get; set; }
1209         public Object? data { get; set; }
1210
1211         protected void add_diagnostic (Diagnostic diag) {
1212             if (diagnostics == null)
1213                 diagnostics = new Gee.ArrayList<Diagnostic> ();
1214             diagnostics.add (diag);
1215         }
1216
1217         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1218             if (property_name != "diagnostics")
1219                 return default_serialize_property (property_name, value, pspec);
1220
1221             var array = new Json.Array ();
1222             if (diagnostics != null)
1223                 foreach (var text_edit in diagnostics)
1224                     array.add_element (Json.gobject_serialize (text_edit));
1225             return new Json.Node.alloc ().init_array (array);
1226         }
1227     }
1228
1229     public class WorkspaceEdit : Object, Json.Serializable {
1230         public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1231
1232         public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1233             if (property_name != "documentChanges")
1234                 return default_serialize_property (property_name, value, pspec);
1235
1236             var node = new Json.Node (Json.NodeType.ARRAY);
1237             node.init_array (new Json.Array ());
1238             if (documentChanges != null) {
1239                 var array = node.get_array ();
1240                 foreach (var text_edit in documentChanges) {
1241                     array.add_element (Json.gobject_serialize (text_edit));
1242                 }
1243             }
1244             return node;
1245         }
1246     }
1247
1248     [Flags]
1249     public enum SymbolTags {
1250         NONE,
1251         DEPRECATED
1252     }
1253
1254     public class CallHierarchyItem : Object, Json.Serializable {
1255         public string name { get; set; }
1256         public SymbolKind kind { get; set; }
1257         public SymbolTags tags { get; set; }
1258         public string? detail { get; set; }
1259         public string uri { get; set; }
1260         public Range range { get; set; }
1261         public Range selectionRange { get; set; }
1262
1263         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1264             if (property_name != "tags")
1265                 return default_serialize_property (property_name, value, pspec);
1266             var array = new Json.Array ();
1267             if (SymbolTags.DEPRECATED in tags)
1268                 array.add_int_element (SymbolTags.DEPRECATED);
1269             return new Json.Node.alloc ().init_array (array);
1270         }
1271 /*
1272         public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1273             this.name = symbol.get_full_name ();
1274             if (symbol is Vala.Method) {
1275                 if (symbol.parent_symbol is Vala.Namespace)
1276                     this.kind = SymbolKind.Function;
1277                 else
1278                     this.kind = SymbolKind.Method;
1279             } else if (symbol is Vala.Signal) {
1280                 this.kind = SymbolKind.Event;
1281             } else if (symbol is Vala.Constructor) {
1282                 this.kind = SymbolKind.Constructor;
1283             } else {
1284                 this.kind = SymbolKind.Method;
1285             }
1286             var version = symbol.get_attribute ("Version");
1287             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1288                 this.tags |= SymbolTags.DEPRECATED;
1289             }
1290             this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1291             this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1292             this.range = new Range.from_sourceref (symbol.source_reference);
1293             if (symbol.comment != null)
1294                 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1295             if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1296                 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1297             this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1298         }
1299         */
1300     }
1301
1302     public class CallHierarchyIncomingCall : Json.Serializable, Object {
1303         /**
1304          * The method that calls the query method.
1305          */
1306         public CallHierarchyItem from { get; set; }
1307
1308         /**
1309          * The ranges at which the query method is called by `from`.
1310          */
1311         public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1312
1313         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1314             if (property_name == "from")
1315                 return default_serialize_property (property_name, value, pspec);
1316             var array = new Json.Array ();
1317             foreach (var range in fromRanges)
1318                 array.add_element (Json.gobject_serialize (range));
1319             return new Json.Node.alloc ().init_array (array);
1320         }
1321     }
1322
1323     public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1324         /**
1325          * The method that the query method calls.
1326          */
1327         public CallHierarchyItem to { get; set; }
1328
1329         /**
1330          * The ranges at which the method is called by the query method.
1331          */
1332         public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1333
1334         public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1335             if (property_name == "to")
1336                 return default_serialize_property (property_name, value, pspec);
1337             var array = new Json.Array ();
1338             foreach (var range in fromRanges)
1339                 array.add_element (Json.gobject_serialize (range));
1340             return new Json.Node.alloc ().init_array (array);
1341         }
1342     }
1343
1344     public class InlayHintParams : Json.Serializable, Object {
1345         public TextDocumentIdentifier textDocument { get; set; }
1346         public Range range { get; set; }
1347     }
1348
1349     public enum InlayHintKind {
1350         UNSET,
1351         TYPE,
1352         PARAMETER
1353     }
1354
1355     public class InlayHint : Object {
1356         public Position position { get; set; }
1357         public string label { get; set; }
1358         public InlayHintKind kind { get; set; }
1359         public string? tooltip { get; set; }
1360         public bool paddingLeft { get; set; }
1361         public bool paddingRight { get; set; }
1362     }
1363
1364    public  class TypeHierarchyItem : Object, Json.Serializable {
1365         /**
1366          * The name of this item
1367          */
1368         public string name { get; set; }
1369
1370         /**
1371          * The kind of this item
1372          */
1373         public SymbolKind kind { get; set; }
1374
1375         /**
1376          * Tags for this item
1377          */
1378         public SymbolTags tags { get; set; }
1379
1380         /**
1381          * More detail for this item, e.g. the signature of a function.
1382          */
1383         public string? detail { get; set; }
1384
1385         /**
1386          * The resource identifier of this item.
1387          */
1388         public string uri { get; set; }
1389
1390         /**
1391          * The range enclosing this symbol not including leading/trailing
1392          * whitespace, but everything else, e.g. comments and code.
1393          */
1394         public Range range { get; set; }
1395
1396         /**
1397          * The range that should be selected and revealed when this symbol
1398          * is being picked, e.g. the name of a function. Must be contained
1399          * by {@link TypeHierarchyItem.range}
1400          */
1401         public Range selectionRange { get; set; }
1402
1403         private TypeHierarchyItem () {}
1404 /*
1405         public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1406             this.name = symbol.get_full_name ();
1407             if (symbol is Vala.Class)
1408                 this.kind = SymbolKind.Class;
1409             else if (symbol is Vala.Delegate)
1410                 this.kind = SymbolKind.Interface;
1411             else if (symbol is Vala.Enum)
1412                 this.kind = SymbolKind.Enum;
1413             else if (symbol is Vala.ErrorCode)
1414                 this.kind = SymbolKind.EnumMember;
1415             else if (symbol is Vala.ErrorDomain)
1416                 this.kind = SymbolKind.Enum;
1417             else if (symbol is Vala.Interface)
1418                 this.kind = SymbolKind.Interface;
1419             else if (symbol is Vala.Struct)
1420                 this.kind = SymbolKind.Struct;
1421             else if (symbol is Vala.TypeParameter)
1422                 this.kind = SymbolKind.TypeParameter;
1423             else {
1424                 this.kind = SymbolKind.Module;
1425                 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1426             }
1427
1428             var version = symbol.get_attribute ("Version");
1429             if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1430                 this.tags |= SymbolTags.DEPRECATED;
1431             }
1432             this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1433             this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1434             this.range = new Range.from_sourceref (symbol.source_reference);
1435             this.selectionRange = this.range;
1436
1437             // widen range to include all members
1438             if (symbol is Vala.ObjectTypeSymbol) {
1439                 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1440                     if (member.source_reference != null)
1441                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1442                 }
1443             } else if (symbol is Vala.Enum) {
1444                 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1445                     if (member.source_reference != null)
1446                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1447                 }
1448                 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1449                     if (method.source_reference != null)
1450                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1451                 }
1452             } else if (symbol is Vala.ErrorDomain) {
1453                 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1454                     if (member.source_reference != null)
1455                         this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1456                 }
1457                 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1458                     if (method.source_reference != null)
1459                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1460                 }
1461             } else if (symbol is Vala.Struct) {
1462                 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1463                     if (field.source_reference != null)
1464                         this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1465                 }
1466                 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1467                     if (method.source_reference != null)
1468                         this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1469                 }
1470             }
1471         }
1472         */
1473     }
1474 }