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