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>
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.
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.
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/>.
23 * Defines how the host (editor) should sync document changes to the language server.
25 [CCode (default_value = "LSP_TEXT_DOCUMENT_SYNC_KIND_Unset")]
26 public enum TextDocumentSyncKind {
29 * Documents should not be synced at all.
33 * Documents are synced by always sending the full content of the document.
37 * Documents are synced by sending the full content on open. After that only incremental
38 * updates to the document are sent.
43 public enum DiagnosticSeverity {
54 * Reports an information.
64 public class Position : Object, Gee.Comparable<Position> {
66 public Position(uint line, uint chr)
72 * Line position in a document (zero-based).
74 public uint line { get; set; default = -1; }
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`.
81 * If the character value is greater than the line length it defaults back to the
84 public uint character { get; set; default = -1; }
86 public int compare_to (Position other) {
88 return line > other.line ? 1 :
90 (character > other.character ? 1 :
91 (character == other.character ? 0 : -1)) : -1);
93 public bool equals(Position o) {
94 return o.line == this.line && o.character == this.character;
97 public string to_string () {
98 return @"$line:$character";
101 public Position.from_libvala (Vala.SourceLocation sloc) {
102 line = sloc.line - 1;
103 character = sloc.column;
106 public Position dup () {
107 return this.translate ();
110 public Position translate (int dl = 0, int dc = 0) {
111 return new Position (this.character + dc, this.character + dc) ;
115 public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
117 public Range.simple(uint line, uint pos) {
118 var p = new Position (line,pos);
124 * The range's start position.
126 public Position start { get; set; }
129 * The range's end position.
131 public Position end { get; set; }
133 private string? filename;
135 public string to_string () { return (filename != null ? @"$filename:" : "") + @"$start -> $end"; }
137 public Range.from_pos (Position pos) {
139 this.end = pos.dup ();
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;
149 public uint hash () {
150 return this.to_string ().hash ();
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);
160 public int compare_to (Range other) {
161 return start.compare_to (other.start);
165 * Return a new range that includes `this` and `other`.
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,
172 if (filename == other.filename)
173 range.filename = filename;
177 public bool contains (Position pos) {
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");
186 public class Diagnostic : Object {
188 public Diagnostic.simple ( int line, int character, string message)
190 this.message = message;
191 this.severity = DiagnosticSeverity.Error;
192 this.range = new Range.simple(line, character );
198 * The range at which the message applies.
200 public Range range { get; set; }
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.
206 public DiagnosticSeverity severity { get; set; }
209 * The diagnostic's code. Can be omitted.
211 public string? code { get; set; }
214 * A human-readable string describing the source of this
215 * diagnostic, e.g. 'typescript' or 'super lint'.
217 public string? source { get; set; }
220 * The diagnostic's message.
222 public string message { get; set; }
225 public string category {
227 switch(this.severity) {
229 case DiagnosticSeverity.Error :
231 case DiagnosticSeverity.Warning :
232 return this.message.contains("deprecated") ? "DEPR" : "WARN";
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());
247 public string to_string()
249 return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
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.
258 public class TextDocumentContentChangeEvent : Object {
259 public Range? range { get; set; }
260 public int rangeLength { get; set; }
261 public string text { get; set; }
264 public enum MessageType {
274 * An information message.
283 public class TextDocumentIdentifier : Object {
284 public string uri { get; set; }
287 public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
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).
295 * The version number of a document will increase after each change, including
296 * undo/redo. The number doesn't need to be consecutive.
298 public int version { get; set; default = -1; }
301 public class TextDocumentPositionParams : Object {
302 public TextDocumentIdentifier textDocument { get; set; }
303 public Position position { get; set; }
306 public class ReferenceParams : TextDocumentPositionParams {
307 public class ReferenceContext : Object {
308 public bool includeDeclaration { get; set; }
310 public ReferenceContext? context { get; set; }
313 public class Location : Object {
314 public string uri { get; set; }
315 public Range range { get; set; }
317 public Location.from_sourceref (Vala.SourceReference sref) {
318 this (sref.file.filename, new Range.from_sourceref (sref));
321 public Location (string filename, Range range) {
322 this.uri = File.new_for_commandline_arg (filename).get_uri ();
327 [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
328 public enum DocumentHighlightKind {
334 public class DocumentHighlight : Object {
335 public Range range { get; set; }
336 public DocumentHighlightKind kind { get; set; }
339 public class DocumentSymbolParams: Object {
340 public TextDocumentIdentifier textDocument { get; set; }
343 public class DocumentSymbol : Object, Json.Serializable {
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; }
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;
355 private DocumentSymbol () {}
358 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
359 * @param sym the symbol
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));
375 this.name = sym.name;
376 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
378 this.selectionRange = new Range.from_sourceref (sym.source_reference);
379 this.deprecated = sym.version.deprecated;
382 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
383 base.set_property (pspec.get_name (), value);
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);
392 public unowned ParamSpec? find_property (string name) {
393 return this.get_class ().find_property (name);
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));
408 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
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);
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 ());
419 //GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
420 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
422 property_node.get_array ().foreach_element ((array, index, element) => {
424 var add= Json.gobject_deserialize ( typeof (DocumentSymbol), array.get_element(index)) as DocumentSymbol;
425 arguments.append( add);
430 value.set_object (arguments);
433 public string symbol_icon {
436 return this.kind.icon();
440 public string tooltip {
442 //GLib.debug("%s : %s", this.name, this.detail);
443 //var detail = this.detail == "" ? (this.kind.to_string() + ": " + this.name) : this.detail;
444 return "" + this.kind.to_string().replace( "LSP_SYMBOL_KIND_", "" ) + "\n" +
445 GLib.Markup.escape_text(this.detail + "\nline: " + this.range.start.line.to_string());
449 public string sort_key {
451 return this.kind.sort_key().to_string() + "=" + this.name;
455 public DocumentSymbol? containsLine(uint line, uint chr)
457 if (!this.range.contains(new Position(line, chr))) {
461 for(var i = 0; i < this.children.get_n_items();i++) {
462 var el = (DocumentSymbol)this.children.get_item(i);
463 var ret = el.containsLine(line,chr);
471 // does not compare children...
472 public bool equals(DocumentSymbol sym) {
473 return this.name == sym.name &&
474 this.kind == sym.kind &&
475 this.detail == sym.detail &&
476 sym.range.equals(this.range);
479 public static void copyList(GLib.ListStore source, GLib.ListStore target)
481 //GLib.debug("copyList source=%d target=%d", (int)source.get_n_items(), (int)target.get_n_items());
483 while (i < source.get_n_items()) {
484 //GLib.debug("copyList compare %d", i);
485 if (i >= target.get_n_items()) {
486 //GLib.debug("copyList append");
487 target.append(source.get_item(i));
491 var sel = (Lsp.DocumentSymbol) source.get_item(i);
492 var tel = (Lsp.DocumentSymbol) target.get_item(i);
493 if (!sel.equals(tel)) {
494 //GLib.debug("copyList replace");
496 target.insert(i, sel);
501 if (sel.children.get_n_items() < 1 && tel.children.get_n_items() < 1) {
503 //GLib.debug("copyList same noChlidren %s", sel.name);
507 //GLib.debug("copyList same = updateChildren %s", sel.name);
509 // they are the same (ignoring children
510 copyList(sel.children,tel.children);
514 // remove target items, that dont exist anymore
515 while (i < target.get_n_items()) {
516 //GLib.debug("copyList remove");
527 public class SymbolInformation : Object {
528 public string name { get; set; }
529 public SymbolKind kind { get; set; }
530 public Location location { get; set; }
531 public string? containerName { get; set; }
533 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
534 this.name = dsym.name;
535 this.kind = dsym.kind;
536 // this.location = new Location (uri, dsym.range);
537 this.containerName = dsym.parent_name;
541 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
542 public enum SymbolKind {
570 public string icon () {
571 return "lang-" + this.to_string().replace( "LSP_SYMBOL_KIND_", "" ).down() + "-symbolic";
574 public int sort_key() {
577 case Enum : return 1;
578 case Class: return 2;
580 case Constructor : return 1;
581 case Method : return 2;
582 case Field : return 3;
583 case Property : return 3;
595 public class CompletionList : Object, Json.Serializable {
596 public bool isIncomplete { get; set; }
597 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
599 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
600 base.set_property (pspec.get_name (), value);
603 public new Value Json.Serializable.get_property (ParamSpec pspec) {
604 Value val = Value(pspec.value_type);
605 base.get_property (pspec.get_name (), ref val);
609 public unowned ParamSpec? find_property (string name) {
610 return this.get_class ().find_property (name);
613 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
614 if (property_name != "items")
615 return default_serialize_property (property_name, value, pspec);
616 var node = new Json.Node (Json.NodeType.ARRAY);
617 node.init_array (new Json.Array ());
618 var array = node.get_array ();
619 foreach (var child in items)
620 array.add_element (Json.gobject_serialize (child));
624 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
625 error ("deserialization not supported");
629 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
630 public enum CompletionTriggerKind {
632 * Completion was triggered by typing an identifier (24x7 code
633 * complete), manual invocation (e.g Ctrl+Space) or via API.
638 * Completion was triggered by a trigger character specified by
639 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
641 TriggerCharacter = 2,
644 * Completion was re-triggered as the current completion list is incomplete.
646 TriggerForIncompleteCompletions = 3
649 public class CompletionContext : Object {
650 public CompletionTriggerKind triggerKind { get; set;}
651 public string? triggerCharacter { get; set; }
654 public class CompletionParams : TextDocumentPositionParams {
656 * The completion context. This is only available if the client specifies
657 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
659 public CompletionContext? context { get; set; }
662 public enum CompletionItemTag {
663 // Render a completion as obsolete, usually using a strike-out.
667 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
668 public enum InsertTextFormat {
670 * The primary text to be inserted is treated as a plain string.
675 * The primary text to be inserted is treated as a snippet.
677 * A snippet can define tab stops and placeholders with `$1`, `$2`
678 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
679 * the end of the snippet. Placeholders with equal identifiers are linked,
680 * that is typing in one will update others too.
685 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
686 public string label { get; set; }
687 public CompletionItemKind kind { get; set; }
688 public string detail { get; set; }
689 public MarkupContent? documentation { get; set; }
690 public bool deprecated { get; set; }
691 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
692 public string? insertText { get; set; }
693 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
696 private CompletionItem () {}
698 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
699 this.label = keyword;
700 this.kind = CompletionItemKind.Keyword;
701 this.insertText = insert_text;
702 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
703 this.insertTextFormat = InsertTextFormat.Snippet;
704 if (documentation != null)
705 this.documentation = new MarkupContent.from_plaintext (documentation);
706 this._hash = @"$label $kind".hash ();
710 * A completion suggestion from an existing Vala symbol.
712 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
713 * @param sym the symbol itself
714 * @param scope the scope to display this in
715 * @param kind the kind of completion to display
716 * @param documentation the documentation to display
717 * @param label_override if non-null, override the displayed symbol name with this
720 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
721 CompletionItemKind kind,
722 Vls.DocComment? documentation, string? label_override = null) {
723 this.label = label_override ?? sym.name;
725 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
726 this._hash = @"$label $kind".hash ();
728 if (documentation != null)
729 this.documentation = new MarkupContent.from_markdown (documentation.body);
731 var version = sym.get_attribute ("Version");
732 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
733 this.tags.add (CompletionItemTag.Deprecated);
734 this.deprecated = true;
739 * A completion suggestion from a data type and a synthetic symbol name.
741 * @param symbol_type the data type of the symbol
742 * @param symbol_name the name of the synthetic symbol
743 * @param scope the scope that this completion item is displayed in, or null
744 * @param kind the type of completion to display
745 * @param documentation the documentation for this symbol, or null
748 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
749 CompletionItemKind kind, Vls.DocComment? documentation) {
750 this.label = symbol_name;
752 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
753 this._hash = @"$label $kind".hash ();
755 if (documentation != null)
756 this.documentation = new MarkupContent.from_markdown (documentation.body);
760 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
761 string label, CompletionItemKind kind,
763 Vls.DocComment? documentation) {
766 this.insertText = insert_text;
767 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
768 this.insertTextFormat = InsertTextFormat.Snippet;
769 this._hash = @"$label $kind".hash ();
770 if (documentation != null)
771 this.documentation = new MarkupContent.from_markdown (documentation.body);
775 public uint hash () {
779 public bool equal_to (CompletionItem other) {
780 return other.label == this.label && other.kind == this.kind;
783 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
784 base.set_property (pspec.get_name (), value);
787 public new Value Json.Serializable.get_property (ParamSpec pspec) {
788 Value val = Value(pspec.value_type);
789 base.get_property (pspec.get_name (), ref val);
793 public unowned ParamSpec? find_property (string name) {
794 return this.get_class ().find_property (name);
797 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
798 if (property_name != "tags")
799 return default_serialize_property (property_name, value, pspec);
801 var node = new Json.Node (Json.NodeType.ARRAY);
802 node.init_array (new Json.Array ());
803 var array = node.get_array ();
804 foreach (var tag in this.tags) {
805 array.add_int_element (tag);
810 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
812 if (property_name != "tags") {
813 return default_deserialize_property (property_name, out value, pspec, property_node);
815 value = GLib.Value (typeof(Gee.ArrayList));
816 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
817 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
821 var arguments = new Gee.ArrayList<CompletionItemTag>();
823 property_node.get_array ().foreach_element ((array, index, element) => {
825 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
827 warning ("argument %u to command could not be deserialized: %s", index, e.message);
831 value.set_object (arguments);
836 public class MarkupContent : Object {
837 public string kind { get; set; }
838 public string value { get; set; }
840 private MarkupContent () {}
843 * Create a MarkupContent with plain text.
845 public MarkupContent.from_plaintext (string doc) {
846 this.kind = "plaintext";
851 * Create a MarkupContent with markdown text.
853 public MarkupContent.from_markdown (string doc) {
854 this.kind = "markdown";
859 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
860 public enum CompletionItemKind {
889 * Capabilities of the client/editor for `textDocument/documentSymbol`
891 public class DocumentSymbolCapabilities : Object {
892 public bool hierarchicalDocumentSymbolSupport { get; set; }
896 * Capabilities of the client/editor for `textDocument/rename`
898 public class RenameClientCapabilities : Object {
899 public bool prepareSupport { get; set; }
903 * Capabilities of the client/editor pertaining to language features.
905 public class TextDocumentClientCapabilities : Object {
906 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
907 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
911 * Capabilities of the client/editor.
913 public class ClientCapabilities : Object {
914 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
917 public class InitializeParams : Object {
918 public int processId { get; set; }
919 public string? rootPath { get; set; }
920 public string? rootUri { get; set; }
921 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
924 public class SignatureInformation : Object, Json.Serializable {
925 public string label { get; set; }
926 public MarkupContent documentation { get; set; }
928 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
930 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
931 base.set_property (pspec.get_name (), value);
934 public new Value Json.Serializable.get_property (ParamSpec pspec) {
935 Value val = Value(pspec.value_type);
936 base.get_property (pspec.get_name (), ref val);
940 public unowned ParamSpec? find_property (string name) {
941 return this.get_class ().find_property (name);
944 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
945 if (property_name != "parameters")
946 return default_serialize_property (property_name, value, pspec);
947 var node = new Json.Node (Json.NodeType.ARRAY);
948 node.init_array (new Json.Array ());
949 var array = node.get_array ();
950 foreach (var child in parameters)
951 array.add_element (Json.gobject_serialize (child));
955 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
956 error ("deserialization not supported");
960 public class SignatureHelp : Object, Json.Serializable {
961 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
962 public int activeSignature { get; set; }
963 public int activeParameter { get; set; }
965 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
966 if (property_name != "signatures")
967 return default_serialize_property (property_name, value, pspec);
969 var node = new Json.Node (Json.NodeType.ARRAY);
970 node.init_array (new Json.Array ());
971 var array = node.get_array ();
972 foreach (var child in signatures)
973 array.add_element (Json.gobject_serialize (child));
977 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
978 error ("deserialization not supported");
982 public class ParameterInformation : Object {
983 public string label { get; set; }
984 public MarkupContent documentation { get; set; }
987 public class MarkedString : Object {
988 public MarkedString(string language, string value)
990 this.language = language;
992 GLib.debug("new marked string %s : %s", language, value);
994 public string language { get; set; }
995 public string value { get; set; }
998 public class Hover : Object, Json.Serializable {
999 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
1000 public Range range { get; set; }
1002 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
1003 base.set_property (pspec.get_name (), value);
1006 public new Value Json.Serializable.get_property (ParamSpec pspec) {
1007 Value val = Value(pspec.value_type);
1008 base.get_property (pspec.get_name (), ref val);
1012 public unowned ParamSpec? find_property (string name) {
1013 return this.get_class ().find_property (name);
1016 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
1017 if (property_name != "contents")
1018 return default_serialize_property (property_name, value, pspec);
1019 var node = new Json.Node (Json.NodeType.ARRAY);
1020 node.init_array (new Json.Array ());
1021 var array = node.get_array ();
1022 foreach (var child in contents) {
1023 if (child.language != null)
1024 array.add_element (Json.gobject_serialize (child));
1026 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
1031 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
1033 if (property_name == "contents") {
1034 value = GLib.Value (typeof(Gee.ArrayList));
1035 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1036 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1039 var contents = new Gee.ArrayList<MarkedString>();
1041 property_node.get_array ().foreach_element ((array, index, element) => {
1042 var add = new MarkedString(
1043 array.get_object_element(index).get_string_member("language"),
1044 array.get_object_element(index).get_string_member("value")
1047 contents.add ( add );
1050 value.set_object (contents);
1054 return default_deserialize_property (property_name, out value, pspec, property_node);
1059 * A textual edit applicable to a text document.
1061 public class TextEdit : Object {
1063 * The range of the text document to be manipulated. To insert
1064 * text into a document create a range where ``start === end``.
1066 public Range range { get; set; }
1069 * The string to be inserted. For delete operations use an
1072 public string newText { get; set; }
1074 public TextEdit (Range range, string new_text = "") {
1076 this.newText = new_text;
1081 * Describes textual changes on a single text document. The text document is
1082 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
1083 * check the text document version before an edit is applied. A
1084 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
1085 * applied move the document to version ``Si+1``. So the creator of a
1086 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
1087 * of ordering. However the edits must be non overlapping.
1089 public class TextDocumentEdit : Object, Json.Serializable {
1091 * The text document to change.
1093 public VersionedTextDocumentIdentifier textDocument { get; set; }
1096 * The edits to be applied.
1098 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
1100 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
1101 this.textDocument = text_document;
1104 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1105 if (property_name != "edits")
1106 return default_serialize_property (property_name, value, pspec);
1108 var node = new Json.Node (Json.NodeType.ARRAY);
1109 node.init_array (new Json.Array ());
1110 var array = node.get_array ();
1111 foreach (var text_edit in edits) {
1112 array.add_element (Json.gobject_serialize (text_edit));
1117 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1118 error ("deserialization not supported");
1122 public abstract class CommandLike : Object, Json.Serializable {
1124 * The identifier of the actual command handler.
1126 public string command { get; set; }
1129 * Arguments that the command handler should be invoked with.
1131 public Array<Variant>? arguments { get; set; }
1133 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1134 if (property_name != "arguments" || arguments == null)
1135 return default_serialize_property (property_name, value, pspec);
1137 var array = new Json.Array ();
1138 for (int i = 0; i < arguments.length; i++)
1139 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1141 var node = new Json.Node (Json.NodeType.ARRAY);
1142 node.set_array (array);
1146 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1148 if (property_name == "arguments") {
1149 value = GLib.Value (typeof(Array));
1150 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1151 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1155 var arguments = new Array<Variant> ();
1157 property_node.get_array ().foreach_element ((array, index, element) => {
1159 arguments.append_val (Json.gvariant_deserialize (element, null));
1161 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1165 value.set_boxed (arguments);
1167 } else if (property_name == "command") {
1168 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1169 if (property_node.get_value_type () != typeof (string)) {
1171 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1175 value = property_node.get_string ();
1178 return default_deserialize_property (property_name, out value, pspec, property_node);
1183 public class ExecuteCommandParams : CommandLike {
1187 * Represents a reference to a command. Provides a title which will be used
1188 * to represent a command in the UI. Commands are identified by a string
1189 * identifier. The recommended way to handle commands is to implement their
1190 * execution on the server side if the client and server provides the
1191 * corresponding capabilities. Alternatively the tool extension code could
1192 * handle the command. The protocol currently doesn’t specify a set of
1193 * well-known commands.
1195 public class Command : CommandLike {
1197 * The title of the command, like `save`.
1199 public string title { get; set; }
1203 * A code lens represents a command that should be shown along with
1204 * source text, like the number of references, a way to run tests, etc.
1206 * A code lens is _unresolved_ when no command is associated to it. For
1207 * performance reasons the creation of a code lens and resolving should be done
1210 public class CodeLens : Object {
1212 * The range in which this code lens is valid. Should only span a single
1215 public Range range { get; set; }
1218 * The command this code lens represents.
1220 public Command? command { get; set; }
1223 public class DocumentRangeFormattingParams : Object {
1224 public TextDocumentIdentifier textDocument { get; set; }
1225 public Range? range { get; set; }
1226 public FormattingOptions options { get; set; }
1229 public class FormattingOptions : Object {
1230 public uint tabSize { get; set; }
1231 public bool insertSpaces { get; set; }
1232 public bool trimTrailingWhitespace { get; set; }
1233 public bool insertFinalNewline { get; set; }
1234 public bool trimFinalNewlines { get; set; }
1237 public class CodeActionParams : Object {
1238 public TextDocumentIdentifier textDocument { get; set; }
1239 public Range range { get; set; }
1240 public CodeActionContext context { get; set; }
1244 public class CodeActionContext : Object, Json.Serializable {
1245 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1246 public string[]? only { get; set; }
1248 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1249 if (property_name != "diagnostics")
1250 return default_deserialize_property (property_name, out value, pspec, property_node);
1251 var diags = new Gee.ArrayList<Diagnostic> ();
1252 property_node.get_array ().foreach_element ((array, index, element) => {
1254 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1256 warning ("argument %u could not be deserialized: %s", index, e.message);
1266 public class Diagnostics : Object, Json.Serializable
1268 public Diagnostics()
1270 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1275 public string uri { get; set; }
1277 public int version { get; set; default = 0; }
1278 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1280 public string filename {
1282 return File.new_for_uri (this.uri).get_path();
1287 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1288 if (property_name == "diagnostics") {
1289 val = GLib.Value (typeof(Gee.ArrayList));
1290 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1293 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1294 val.set_object(diags);
1295 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1301 property_node.get_array ().foreach_element ((array, index, element) => {
1303 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1305 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1308 val.set_object(diags);
1313 return default_deserialize_property (property_name, out val, pspec, property_node);
1321 public class CodeAction : Object, Json.Serializable {
1322 public string title { get; set; }
1323 public string? kind { get; set; }
1324 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1325 public bool isPreferred { get; set; }
1326 public WorkspaceEdit? edit { get; set; }
1327 public Command? command { get; set; }
1328 public Object? data { get; set; }
1330 protected void add_diagnostic (Diagnostic diag) {
1331 if (diagnostics == null)
1332 diagnostics = new Gee.ArrayList<Diagnostic> ();
1333 diagnostics.add (diag);
1336 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1337 if (property_name != "diagnostics")
1338 return default_serialize_property (property_name, value, pspec);
1340 var array = new Json.Array ();
1341 if (diagnostics != null)
1342 foreach (var text_edit in diagnostics)
1343 array.add_element (Json.gobject_serialize (text_edit));
1344 return new Json.Node.alloc ().init_array (array);
1348 public class WorkspaceEdit : Object, Json.Serializable {
1349 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1351 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1352 if (property_name != "documentChanges")
1353 return default_serialize_property (property_name, value, pspec);
1355 var node = new Json.Node (Json.NodeType.ARRAY);
1356 node.init_array (new Json.Array ());
1357 if (documentChanges != null) {
1358 var array = node.get_array ();
1359 foreach (var text_edit in documentChanges) {
1360 array.add_element (Json.gobject_serialize (text_edit));
1368 public enum SymbolTags {
1373 public class CallHierarchyItem : Object, Json.Serializable {
1374 public string name { get; set; }
1375 public SymbolKind kind { get; set; }
1376 public SymbolTags tags { get; set; }
1377 public string? detail { get; set; }
1378 public string uri { get; set; }
1379 public Range range { get; set; }
1380 public Range selectionRange { get; set; }
1382 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1383 if (property_name != "tags")
1384 return default_serialize_property (property_name, value, pspec);
1385 var array = new Json.Array ();
1386 if (SymbolTags.DEPRECATED in tags)
1387 array.add_int_element (SymbolTags.DEPRECATED);
1388 return new Json.Node.alloc ().init_array (array);
1391 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1392 this.name = symbol.get_full_name ();
1393 if (symbol is Vala.Method) {
1394 if (symbol.parent_symbol is Vala.Namespace)
1395 this.kind = SymbolKind.Function;
1397 this.kind = SymbolKind.Method;
1398 } else if (symbol is Vala.Signal) {
1399 this.kind = SymbolKind.Event;
1400 } else if (symbol is Vala.Constructor) {
1401 this.kind = SymbolKind.Constructor;
1403 this.kind = SymbolKind.Method;
1405 var version = symbol.get_attribute ("Version");
1406 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1407 this.tags |= SymbolTags.DEPRECATED;
1409 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1410 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1411 this.range = new Range.from_sourceref (symbol.source_reference);
1412 if (symbol.comment != null)
1413 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1414 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1415 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1416 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1421 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1423 * The method that calls the query method.
1425 public CallHierarchyItem from { get; set; }
1428 * The ranges at which the query method is called by `from`.
1430 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1432 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1433 if (property_name == "from")
1434 return default_serialize_property (property_name, value, pspec);
1435 var array = new Json.Array ();
1436 foreach (var range in fromRanges)
1437 array.add_element (Json.gobject_serialize (range));
1438 return new Json.Node.alloc ().init_array (array);
1442 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1444 * The method that the query method calls.
1446 public CallHierarchyItem to { get; set; }
1449 * The ranges at which the method is called by the query method.
1451 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1453 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1454 if (property_name == "to")
1455 return default_serialize_property (property_name, value, pspec);
1456 var array = new Json.Array ();
1457 foreach (var range in fromRanges)
1458 array.add_element (Json.gobject_serialize (range));
1459 return new Json.Node.alloc ().init_array (array);
1463 public class InlayHintParams : Json.Serializable, Object {
1464 public TextDocumentIdentifier textDocument { get; set; }
1465 public Range range { get; set; }
1468 public enum InlayHintKind {
1474 public class InlayHint : Object {
1475 public Position position { get; set; }
1476 public string label { get; set; }
1477 public InlayHintKind kind { get; set; }
1478 public string? tooltip { get; set; }
1479 public bool paddingLeft { get; set; }
1480 public bool paddingRight { get; set; }
1483 public class TypeHierarchyItem : Object, Json.Serializable {
1485 * The name of this item
1487 public string name { get; set; }
1490 * The kind of this item
1492 public SymbolKind kind { get; set; }
1495 * Tags for this item
1497 public SymbolTags tags { get; set; }
1500 * More detail for this item, e.g. the signature of a function.
1502 public string? detail { get; set; }
1505 * The resource identifier of this item.
1507 public string uri { get; set; }
1510 * The range enclosing this symbol not including leading/trailing
1511 * whitespace, but everything else, e.g. comments and code.
1513 public Range range { get; set; }
1516 * The range that should be selected and revealed when this symbol
1517 * is being picked, e.g. the name of a function. Must be contained
1518 * by {@link TypeHierarchyItem.range}
1520 public Range selectionRange { get; set; }
1522 private TypeHierarchyItem () {}
1524 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1525 this.name = symbol.get_full_name ();
1526 if (symbol is Vala.Class)
1527 this.kind = SymbolKind.Class;
1528 else if (symbol is Vala.Delegate)
1529 this.kind = SymbolKind.Interface;
1530 else if (symbol is Vala.Enum)
1531 this.kind = SymbolKind.Enum;
1532 else if (symbol is Vala.ErrorCode)
1533 this.kind = SymbolKind.EnumMember;
1534 else if (symbol is Vala.ErrorDomain)
1535 this.kind = SymbolKind.Enum;
1536 else if (symbol is Vala.Interface)
1537 this.kind = SymbolKind.Interface;
1538 else if (symbol is Vala.Struct)
1539 this.kind = SymbolKind.Struct;
1540 else if (symbol is Vala.TypeParameter)
1541 this.kind = SymbolKind.TypeParameter;
1543 this.kind = SymbolKind.Module;
1544 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1547 var version = symbol.get_attribute ("Version");
1548 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1549 this.tags |= SymbolTags.DEPRECATED;
1551 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1552 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1553 this.range = new Range.from_sourceref (symbol.source_reference);
1554 this.selectionRange = this.range;
1556 // widen range to include all members
1557 if (symbol is Vala.ObjectTypeSymbol) {
1558 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1559 if (member.source_reference != null)
1560 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1562 } else if (symbol is Vala.Enum) {
1563 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1564 if (member.source_reference != null)
1565 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1567 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1568 if (method.source_reference != null)
1569 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1571 } else if (symbol is Vala.ErrorDomain) {
1572 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1573 if (member.source_reference != null)
1574 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1576 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1577 if (method.source_reference != null)
1578 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1580 } else if (symbol is Vala.Struct) {
1581 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1582 if (field.source_reference != null)
1583 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1585 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1586 if (method.source_reference != null)
1587 this.range = this.range.union (new Range.from_sourceref (method.source_reference));