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