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 GLib.Markup.escape_text(this.detail + "\nline: " + this.range.start.line.to_string());
448 public string sort_key {
450 return this.kind.sort_key().to_string() + "=" + this.name;
454 public DocumentSymbol? containsLine(uint line, uint chr)
456 if (!this.range.contains(new Position(line, chr))) {
460 for(var i = 0; i < this.children.get_n_items();i++) {
461 var el = (DocumentSymbol)this.children.get_item(i);
462 var ret = el.containsLine(line,chr);
470 public bool equals(DocumentSymbol sym) {
471 return this.name == sym.name &&
472 this.kind == sym.kind &&
473 sym.range.equals(this.range);
476 public static void copyList(GLib.ListStore source, GLib.ListStore target)
479 while (i < source.get_n_items()) {
480 if (i >= target.get_n_items()) {
481 target.append(source.get_item(i));
485 var sel = (Lsp.DocumentSymbol) source.get_item(i);
486 var tel = (Lsp.DocumentSymbol) target.get_item(i);
487 if (!sel.equals(tel)) {
489 target.insert(i, tel);
494 // they are the same (ignoring children
495 copyList(sel).children,tel.children);
499 // remove target items, that dont exist anymore
500 while (i < target.get_n_items()) {
514 public class SymbolInformation : Object {
515 public string name { get; set; }
516 public SymbolKind kind { get; set; }
517 public Location location { get; set; }
518 public string? containerName { get; set; }
520 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
521 this.name = dsym.name;
522 this.kind = dsym.kind;
523 // this.location = new Location (uri, dsym.range);
524 this.containerName = dsym.parent_name;
528 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
529 public enum SymbolKind {
557 public string icon () {
561 // case SymbolKind.Text: return "completion-snippet-symbolic";
562 case SymbolKind.Method: return "lang-method-symbolic";
563 case SymbolKind.Function: return "lang-function-symbolic";
564 case SymbolKind.Constructor: return "lang-method-symbolic";
565 case SymbolKind.Field: return "lang-struct-field-symbolic";
566 case SymbolKind.Variable: return "lang-variable-symbolic";
567 case SymbolKind.Class: return "lang-class-symbolic";
568 case SymbolKind.Interface: return "lang-class-symbolic";
569 case SymbolKind.Module: return "lang-namespace-symbolic";
570 case SymbolKind.Property:return "lang-struct-field-symbolic";
571 //case SymbolKind.Unit: return "lang-variable-symbolic";
572 //case SymbolKind.Value: return "lang-variable-symbolic";
573 case SymbolKind.Enum: return "lang-enum-symbolic";
574 //case SymbolKind.Keyword: return "completion-word-symbolic";
575 //case SymbolKind.Snippet: return "completion-snippet-symbolic";
577 //case SymbolKind.Color: return "lang-typedef-symbolic";
578 case SymbolKind.File:return "lang-typedef-symbolic";
579 //case SymbolKind.Reference: return "lang-typedef-symbolic";
580 //case SymbolKind.Folder:return "lang-typedef-symbolic";
581 case SymbolKind.EnumMember: return "lang-typedef-symbolic";
582 case SymbolKind.Constant:return "lang-typedef-symbolic";
583 case SymbolKind.Struct: return "lang-struct-symbolic";
584 case SymbolKind.Event:return "lang-typedef-symbolic";
585 case SymbolKind.Operator:return "lang-typedef-symbolic";
586 case SymbolKind.TypeParameter:return "lang-typedef-symbolic";
589 return "completion-snippet-symbolic";
593 public int sort_key() {
596 case Enum : return 1;
597 case Class: return 2;
599 case Constructor : return 1;
600 case Method : return 2;
601 case Field : return 3;
602 case Property : return 3;
614 public class CompletionList : Object, Json.Serializable {
615 public bool isIncomplete { get; set; }
616 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
618 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
619 base.set_property (pspec.get_name (), value);
622 public new Value Json.Serializable.get_property (ParamSpec pspec) {
623 Value val = Value(pspec.value_type);
624 base.get_property (pspec.get_name (), ref val);
628 public unowned ParamSpec? find_property (string name) {
629 return this.get_class ().find_property (name);
632 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
633 if (property_name != "items")
634 return default_serialize_property (property_name, value, pspec);
635 var node = new Json.Node (Json.NodeType.ARRAY);
636 node.init_array (new Json.Array ());
637 var array = node.get_array ();
638 foreach (var child in items)
639 array.add_element (Json.gobject_serialize (child));
643 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
644 error ("deserialization not supported");
648 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
649 public enum CompletionTriggerKind {
651 * Completion was triggered by typing an identifier (24x7 code
652 * complete), manual invocation (e.g Ctrl+Space) or via API.
657 * Completion was triggered by a trigger character specified by
658 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
660 TriggerCharacter = 2,
663 * Completion was re-triggered as the current completion list is incomplete.
665 TriggerForIncompleteCompletions = 3
668 public class CompletionContext : Object {
669 public CompletionTriggerKind triggerKind { get; set;}
670 public string? triggerCharacter { get; set; }
673 public class CompletionParams : TextDocumentPositionParams {
675 * The completion context. This is only available if the client specifies
676 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
678 public CompletionContext? context { get; set; }
681 public enum CompletionItemTag {
682 // Render a completion as obsolete, usually using a strike-out.
686 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
687 public enum InsertTextFormat {
689 * The primary text to be inserted is treated as a plain string.
694 * The primary text to be inserted is treated as a snippet.
696 * A snippet can define tab stops and placeholders with `$1`, `$2`
697 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
698 * the end of the snippet. Placeholders with equal identifiers are linked,
699 * that is typing in one will update others too.
704 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
705 public string label { get; set; }
706 public CompletionItemKind kind { get; set; }
707 public string detail { get; set; }
708 public MarkupContent? documentation { get; set; }
709 public bool deprecated { get; set; }
710 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
711 public string? insertText { get; set; }
712 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
715 private CompletionItem () {}
717 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
718 this.label = keyword;
719 this.kind = CompletionItemKind.Keyword;
720 this.insertText = insert_text;
721 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
722 this.insertTextFormat = InsertTextFormat.Snippet;
723 if (documentation != null)
724 this.documentation = new MarkupContent.from_plaintext (documentation);
725 this._hash = @"$label $kind".hash ();
729 * A completion suggestion from an existing Vala symbol.
731 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
732 * @param sym the symbol itself
733 * @param scope the scope to display this in
734 * @param kind the kind of completion to display
735 * @param documentation the documentation to display
736 * @param label_override if non-null, override the displayed symbol name with this
739 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
740 CompletionItemKind kind,
741 Vls.DocComment? documentation, string? label_override = null) {
742 this.label = label_override ?? sym.name;
744 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
745 this._hash = @"$label $kind".hash ();
747 if (documentation != null)
748 this.documentation = new MarkupContent.from_markdown (documentation.body);
750 var version = sym.get_attribute ("Version");
751 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
752 this.tags.add (CompletionItemTag.Deprecated);
753 this.deprecated = true;
758 * A completion suggestion from a data type and a synthetic symbol name.
760 * @param symbol_type the data type of the symbol
761 * @param symbol_name the name of the synthetic symbol
762 * @param scope the scope that this completion item is displayed in, or null
763 * @param kind the type of completion to display
764 * @param documentation the documentation for this symbol, or null
767 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
768 CompletionItemKind kind, Vls.DocComment? documentation) {
769 this.label = symbol_name;
771 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
772 this._hash = @"$label $kind".hash ();
774 if (documentation != null)
775 this.documentation = new MarkupContent.from_markdown (documentation.body);
779 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
780 string label, CompletionItemKind kind,
782 Vls.DocComment? documentation) {
785 this.insertText = insert_text;
786 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
787 this.insertTextFormat = InsertTextFormat.Snippet;
788 this._hash = @"$label $kind".hash ();
789 if (documentation != null)
790 this.documentation = new MarkupContent.from_markdown (documentation.body);
794 public uint hash () {
798 public bool equal_to (CompletionItem other) {
799 return other.label == this.label && other.kind == this.kind;
802 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
803 base.set_property (pspec.get_name (), value);
806 public new Value Json.Serializable.get_property (ParamSpec pspec) {
807 Value val = Value(pspec.value_type);
808 base.get_property (pspec.get_name (), ref val);
812 public unowned ParamSpec? find_property (string name) {
813 return this.get_class ().find_property (name);
816 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
817 if (property_name != "tags")
818 return default_serialize_property (property_name, value, pspec);
820 var node = new Json.Node (Json.NodeType.ARRAY);
821 node.init_array (new Json.Array ());
822 var array = node.get_array ();
823 foreach (var tag in this.tags) {
824 array.add_int_element (tag);
829 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
831 if (property_name != "tags") {
832 return default_deserialize_property (property_name, out value, pspec, property_node);
834 value = GLib.Value (typeof(Gee.ArrayList));
835 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
836 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
840 var arguments = new Gee.ArrayList<CompletionItemTag>();
842 property_node.get_array ().foreach_element ((array, index, element) => {
844 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
846 warning ("argument %u to command could not be deserialized: %s", index, e.message);
850 value.set_object (arguments);
855 public class MarkupContent : Object {
856 public string kind { get; set; }
857 public string value { get; set; }
859 private MarkupContent () {}
862 * Create a MarkupContent with plain text.
864 public MarkupContent.from_plaintext (string doc) {
865 this.kind = "plaintext";
870 * Create a MarkupContent with markdown text.
872 public MarkupContent.from_markdown (string doc) {
873 this.kind = "markdown";
878 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
879 public enum CompletionItemKind {
908 * Capabilities of the client/editor for `textDocument/documentSymbol`
910 public class DocumentSymbolCapabilities : Object {
911 public bool hierarchicalDocumentSymbolSupport { get; set; }
915 * Capabilities of the client/editor for `textDocument/rename`
917 public class RenameClientCapabilities : Object {
918 public bool prepareSupport { get; set; }
922 * Capabilities of the client/editor pertaining to language features.
924 public class TextDocumentClientCapabilities : Object {
925 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
926 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
930 * Capabilities of the client/editor.
932 public class ClientCapabilities : Object {
933 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
936 public class InitializeParams : Object {
937 public int processId { get; set; }
938 public string? rootPath { get; set; }
939 public string? rootUri { get; set; }
940 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
943 public class SignatureInformation : Object, Json.Serializable {
944 public string label { get; set; }
945 public MarkupContent documentation { get; set; }
947 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
949 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
950 base.set_property (pspec.get_name (), value);
953 public new Value Json.Serializable.get_property (ParamSpec pspec) {
954 Value val = Value(pspec.value_type);
955 base.get_property (pspec.get_name (), ref val);
959 public unowned ParamSpec? find_property (string name) {
960 return this.get_class ().find_property (name);
963 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
964 if (property_name != "parameters")
965 return default_serialize_property (property_name, value, pspec);
966 var node = new Json.Node (Json.NodeType.ARRAY);
967 node.init_array (new Json.Array ());
968 var array = node.get_array ();
969 foreach (var child in parameters)
970 array.add_element (Json.gobject_serialize (child));
974 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
975 error ("deserialization not supported");
979 public class SignatureHelp : Object, Json.Serializable {
980 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
981 public int activeSignature { get; set; }
982 public int activeParameter { get; set; }
984 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
985 if (property_name != "signatures")
986 return default_serialize_property (property_name, value, pspec);
988 var node = new Json.Node (Json.NodeType.ARRAY);
989 node.init_array (new Json.Array ());
990 var array = node.get_array ();
991 foreach (var child in signatures)
992 array.add_element (Json.gobject_serialize (child));
996 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
997 error ("deserialization not supported");
1001 public class ParameterInformation : Object {
1002 public string label { get; set; }
1003 public MarkupContent documentation { get; set; }
1006 public class MarkedString : Object {
1007 public MarkedString(string language, string value)
1009 this.language = language;
1011 GLib.debug("new marked string %s : %s", language, value);
1013 public string language { get; set; }
1014 public string value { get; set; }
1017 public class Hover : Object, Json.Serializable {
1018 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
1019 public Range range { get; set; }
1021 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
1022 base.set_property (pspec.get_name (), value);
1025 public new Value Json.Serializable.get_property (ParamSpec pspec) {
1026 Value val = Value(pspec.value_type);
1027 base.get_property (pspec.get_name (), ref val);
1031 public unowned ParamSpec? find_property (string name) {
1032 return this.get_class ().find_property (name);
1035 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
1036 if (property_name != "contents")
1037 return default_serialize_property (property_name, value, pspec);
1038 var node = new Json.Node (Json.NodeType.ARRAY);
1039 node.init_array (new Json.Array ());
1040 var array = node.get_array ();
1041 foreach (var child in contents) {
1042 if (child.language != null)
1043 array.add_element (Json.gobject_serialize (child));
1045 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
1050 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
1052 if (property_name == "contents") {
1053 value = GLib.Value (typeof(Gee.ArrayList));
1054 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1055 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1058 var contents = new Gee.ArrayList<MarkedString>();
1060 property_node.get_array ().foreach_element ((array, index, element) => {
1061 var add = new MarkedString(
1062 array.get_object_element(index).get_string_member("language"),
1063 array.get_object_element(index).get_string_member("value")
1066 contents.add ( add );
1069 value.set_object (contents);
1073 return default_deserialize_property (property_name, out value, pspec, property_node);
1078 * A textual edit applicable to a text document.
1080 public class TextEdit : Object {
1082 * The range of the text document to be manipulated. To insert
1083 * text into a document create a range where ``start === end``.
1085 public Range range { get; set; }
1088 * The string to be inserted. For delete operations use an
1091 public string newText { get; set; }
1093 public TextEdit (Range range, string new_text = "") {
1095 this.newText = new_text;
1100 * Describes textual changes on a single text document. The text document is
1101 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
1102 * check the text document version before an edit is applied. A
1103 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
1104 * applied move the document to version ``Si+1``. So the creator of a
1105 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
1106 * of ordering. However the edits must be non overlapping.
1108 public class TextDocumentEdit : Object, Json.Serializable {
1110 * The text document to change.
1112 public VersionedTextDocumentIdentifier textDocument { get; set; }
1115 * The edits to be applied.
1117 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
1119 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
1120 this.textDocument = text_document;
1123 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1124 if (property_name != "edits")
1125 return default_serialize_property (property_name, value, pspec);
1127 var node = new Json.Node (Json.NodeType.ARRAY);
1128 node.init_array (new Json.Array ());
1129 var array = node.get_array ();
1130 foreach (var text_edit in edits) {
1131 array.add_element (Json.gobject_serialize (text_edit));
1136 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1137 error ("deserialization not supported");
1141 public abstract class CommandLike : Object, Json.Serializable {
1143 * The identifier of the actual command handler.
1145 public string command { get; set; }
1148 * Arguments that the command handler should be invoked with.
1150 public Array<Variant>? arguments { get; set; }
1152 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1153 if (property_name != "arguments" || arguments == null)
1154 return default_serialize_property (property_name, value, pspec);
1156 var array = new Json.Array ();
1157 for (int i = 0; i < arguments.length; i++)
1158 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1160 var node = new Json.Node (Json.NodeType.ARRAY);
1161 node.set_array (array);
1165 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1167 if (property_name == "arguments") {
1168 value = GLib.Value (typeof(Array));
1169 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1170 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1174 var arguments = new Array<Variant> ();
1176 property_node.get_array ().foreach_element ((array, index, element) => {
1178 arguments.append_val (Json.gvariant_deserialize (element, null));
1180 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1184 value.set_boxed (arguments);
1186 } else if (property_name == "command") {
1187 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1188 if (property_node.get_value_type () != typeof (string)) {
1190 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1194 value = property_node.get_string ();
1197 return default_deserialize_property (property_name, out value, pspec, property_node);
1202 public class ExecuteCommandParams : CommandLike {
1206 * Represents a reference to a command. Provides a title which will be used
1207 * to represent a command in the UI. Commands are identified by a string
1208 * identifier. The recommended way to handle commands is to implement their
1209 * execution on the server side if the client and server provides the
1210 * corresponding capabilities. Alternatively the tool extension code could
1211 * handle the command. The protocol currently doesn’t specify a set of
1212 * well-known commands.
1214 public class Command : CommandLike {
1216 * The title of the command, like `save`.
1218 public string title { get; set; }
1222 * A code lens represents a command that should be shown along with
1223 * source text, like the number of references, a way to run tests, etc.
1225 * A code lens is _unresolved_ when no command is associated to it. For
1226 * performance reasons the creation of a code lens and resolving should be done
1229 public class CodeLens : Object {
1231 * The range in which this code lens is valid. Should only span a single
1234 public Range range { get; set; }
1237 * The command this code lens represents.
1239 public Command? command { get; set; }
1242 public class DocumentRangeFormattingParams : Object {
1243 public TextDocumentIdentifier textDocument { get; set; }
1244 public Range? range { get; set; }
1245 public FormattingOptions options { get; set; }
1248 public class FormattingOptions : Object {
1249 public uint tabSize { get; set; }
1250 public bool insertSpaces { get; set; }
1251 public bool trimTrailingWhitespace { get; set; }
1252 public bool insertFinalNewline { get; set; }
1253 public bool trimFinalNewlines { get; set; }
1256 public class CodeActionParams : Object {
1257 public TextDocumentIdentifier textDocument { get; set; }
1258 public Range range { get; set; }
1259 public CodeActionContext context { get; set; }
1263 public class CodeActionContext : Object, Json.Serializable {
1264 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1265 public string[]? only { get; set; }
1267 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1268 if (property_name != "diagnostics")
1269 return default_deserialize_property (property_name, out value, pspec, property_node);
1270 var diags = new Gee.ArrayList<Diagnostic> ();
1271 property_node.get_array ().foreach_element ((array, index, element) => {
1273 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1275 warning ("argument %u could not be deserialized: %s", index, e.message);
1285 public class Diagnostics : Object, Json.Serializable
1287 public Diagnostics()
1289 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1294 public string uri { get; set; }
1296 public int version { get; set; default = 0; }
1297 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1299 public string filename {
1301 return File.new_for_uri (this.uri).get_path();
1306 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1307 if (property_name == "diagnostics") {
1308 val = GLib.Value (typeof(Gee.ArrayList));
1309 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1312 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1313 val.set_object(diags);
1314 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1320 property_node.get_array ().foreach_element ((array, index, element) => {
1322 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1324 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1327 val.set_object(diags);
1332 return default_deserialize_property (property_name, out val, pspec, property_node);
1340 public class CodeAction : Object, Json.Serializable {
1341 public string title { get; set; }
1342 public string? kind { get; set; }
1343 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1344 public bool isPreferred { get; set; }
1345 public WorkspaceEdit? edit { get; set; }
1346 public Command? command { get; set; }
1347 public Object? data { get; set; }
1349 protected void add_diagnostic (Diagnostic diag) {
1350 if (diagnostics == null)
1351 diagnostics = new Gee.ArrayList<Diagnostic> ();
1352 diagnostics.add (diag);
1355 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1356 if (property_name != "diagnostics")
1357 return default_serialize_property (property_name, value, pspec);
1359 var array = new Json.Array ();
1360 if (diagnostics != null)
1361 foreach (var text_edit in diagnostics)
1362 array.add_element (Json.gobject_serialize (text_edit));
1363 return new Json.Node.alloc ().init_array (array);
1367 public class WorkspaceEdit : Object, Json.Serializable {
1368 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1370 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1371 if (property_name != "documentChanges")
1372 return default_serialize_property (property_name, value, pspec);
1374 var node = new Json.Node (Json.NodeType.ARRAY);
1375 node.init_array (new Json.Array ());
1376 if (documentChanges != null) {
1377 var array = node.get_array ();
1378 foreach (var text_edit in documentChanges) {
1379 array.add_element (Json.gobject_serialize (text_edit));
1387 public enum SymbolTags {
1392 public class CallHierarchyItem : Object, Json.Serializable {
1393 public string name { get; set; }
1394 public SymbolKind kind { get; set; }
1395 public SymbolTags tags { get; set; }
1396 public string? detail { get; set; }
1397 public string uri { get; set; }
1398 public Range range { get; set; }
1399 public Range selectionRange { get; set; }
1401 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1402 if (property_name != "tags")
1403 return default_serialize_property (property_name, value, pspec);
1404 var array = new Json.Array ();
1405 if (SymbolTags.DEPRECATED in tags)
1406 array.add_int_element (SymbolTags.DEPRECATED);
1407 return new Json.Node.alloc ().init_array (array);
1410 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1411 this.name = symbol.get_full_name ();
1412 if (symbol is Vala.Method) {
1413 if (symbol.parent_symbol is Vala.Namespace)
1414 this.kind = SymbolKind.Function;
1416 this.kind = SymbolKind.Method;
1417 } else if (symbol is Vala.Signal) {
1418 this.kind = SymbolKind.Event;
1419 } else if (symbol is Vala.Constructor) {
1420 this.kind = SymbolKind.Constructor;
1422 this.kind = SymbolKind.Method;
1424 var version = symbol.get_attribute ("Version");
1425 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1426 this.tags |= SymbolTags.DEPRECATED;
1428 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1429 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1430 this.range = new Range.from_sourceref (symbol.source_reference);
1431 if (symbol.comment != null)
1432 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1433 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1434 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1435 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1440 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1442 * The method that calls the query method.
1444 public CallHierarchyItem from { get; set; }
1447 * The ranges at which the query method is called by `from`.
1449 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1451 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1452 if (property_name == "from")
1453 return default_serialize_property (property_name, value, pspec);
1454 var array = new Json.Array ();
1455 foreach (var range in fromRanges)
1456 array.add_element (Json.gobject_serialize (range));
1457 return new Json.Node.alloc ().init_array (array);
1461 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1463 * The method that the query method calls.
1465 public CallHierarchyItem to { get; set; }
1468 * The ranges at which the method is called by the query method.
1470 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1472 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1473 if (property_name == "to")
1474 return default_serialize_property (property_name, value, pspec);
1475 var array = new Json.Array ();
1476 foreach (var range in fromRanges)
1477 array.add_element (Json.gobject_serialize (range));
1478 return new Json.Node.alloc ().init_array (array);
1482 public class InlayHintParams : Json.Serializable, Object {
1483 public TextDocumentIdentifier textDocument { get; set; }
1484 public Range range { get; set; }
1487 public enum InlayHintKind {
1493 public class InlayHint : Object {
1494 public Position position { get; set; }
1495 public string label { get; set; }
1496 public InlayHintKind kind { get; set; }
1497 public string? tooltip { get; set; }
1498 public bool paddingLeft { get; set; }
1499 public bool paddingRight { get; set; }
1502 public class TypeHierarchyItem : Object, Json.Serializable {
1504 * The name of this item
1506 public string name { get; set; }
1509 * The kind of this item
1511 public SymbolKind kind { get; set; }
1514 * Tags for this item
1516 public SymbolTags tags { get; set; }
1519 * More detail for this item, e.g. the signature of a function.
1521 public string? detail { get; set; }
1524 * The resource identifier of this item.
1526 public string uri { get; set; }
1529 * The range enclosing this symbol not including leading/trailing
1530 * whitespace, but everything else, e.g. comments and code.
1532 public Range range { get; set; }
1535 * The range that should be selected and revealed when this symbol
1536 * is being picked, e.g. the name of a function. Must be contained
1537 * by {@link TypeHierarchyItem.range}
1539 public Range selectionRange { get; set; }
1541 private TypeHierarchyItem () {}
1543 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1544 this.name = symbol.get_full_name ();
1545 if (symbol is Vala.Class)
1546 this.kind = SymbolKind.Class;
1547 else if (symbol is Vala.Delegate)
1548 this.kind = SymbolKind.Interface;
1549 else if (symbol is Vala.Enum)
1550 this.kind = SymbolKind.Enum;
1551 else if (symbol is Vala.ErrorCode)
1552 this.kind = SymbolKind.EnumMember;
1553 else if (symbol is Vala.ErrorDomain)
1554 this.kind = SymbolKind.Enum;
1555 else if (symbol is Vala.Interface)
1556 this.kind = SymbolKind.Interface;
1557 else if (symbol is Vala.Struct)
1558 this.kind = SymbolKind.Struct;
1559 else if (symbol is Vala.TypeParameter)
1560 this.kind = SymbolKind.TypeParameter;
1562 this.kind = SymbolKind.Module;
1563 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1566 var version = symbol.get_attribute ("Version");
1567 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1568 this.tags |= SymbolTags.DEPRECATED;
1570 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1571 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1572 this.range = new Range.from_sourceref (symbol.source_reference);
1573 this.selectionRange = this.range;
1575 // widen range to include all members
1576 if (symbol is Vala.ObjectTypeSymbol) {
1577 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1578 if (member.source_reference != null)
1579 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1581 } else if (symbol is Vala.Enum) {
1582 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1583 if (member.source_reference != null)
1584 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1586 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1587 if (method.source_reference != null)
1588 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1590 } else if (symbol is Vala.ErrorDomain) {
1591 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1592 if (member.source_reference != null)
1593 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1595 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1596 if (method.source_reference != null)
1597 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1599 } else if (symbol is Vala.Struct) {
1600 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1601 if (field.source_reference != null)
1602 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1604 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1605 if (method.source_reference != null)
1606 this.range = this.range.union (new Range.from_sourceref (method.source_reference));