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