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