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