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 * Line position in a document (zero-based).
68 public uint line { get; set; default = -1; }
71 * Character offset on a line in a document (zero-based). Assuming that the line is
72 * represented as a string, the `character` value represents the gap between the
73 * `character` and `character + 1`.
75 * If the character value is greater than the line length it defaults back to the
78 public uint character { get; set; default = -1; }
80 public int compare_to (Position other) {
81 return line > other.line ? 1 :
83 (character > other.character ? 1 :
84 (character == other.character ? 0 : -1)) : -1);
87 public string to_string () {
88 return @"$line:$character";
91 public Position.from_libvala (Vala.SourceLocation sloc) {
93 character = sloc.column;
96 public Position dup () {
97 return this.translate ();
100 public Position translate (int dl = 0, int dc = 0) {
101 return new Position () {
102 line = this.line + dl,
103 character = this.character + dc
108 public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
110 * The range's start position.
112 public Position start { get; set; }
115 * The range's end position.
117 public Position end { get; set; }
119 private string? filename;
121 public string to_string () { return (filename != null ? @"$filename:" : "") + @"$start -> $end"; }
123 public Range.from_pos (Position pos) {
125 this.end = pos.dup ();
128 public Range.from_sourceref (Vala.SourceReference sref) {
129 this.start = new Position.from_libvala (sref.begin);
130 this.end = new Position.from_libvala (sref.end);
131 this.start.character -= 1;
132 this.filename = sref.file.filename;
135 public uint hash () {
136 return this.to_string ().hash ();
139 public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
141 public int compare_to (Range other) {
142 return start.compare_to (other.start);
146 * Return a new range that includes `this` and `other`.
148 public Range union (Range other) {
149 var range = new Range () {
150 start = start.compare_to (other.start) < 0 ? start : other.start,
151 end = end.compare_to (other.end) < 0 ? other.end : end,
153 if (filename == other.filename)
154 range.filename = filename;
158 public bool contains (Position pos) {
159 return start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
163 public class Diagnostic : Object {
165 * The range at which the message applies.
167 public Range range { get; set; }
170 * The diagnostic's severity. Can be omitted. If omitted it is up to the
171 * client to interpret diagnostics as error, warning, info or hint.
173 public DiagnosticSeverity severity { get; set; }
176 * The diagnostic's code. Can be omitted.
178 public string? code { get; set; }
181 * A human-readable string describing the source of this
182 * diagnostic, e.g. 'typescript' or 'super lint'.
184 public string? source { get; set; }
187 * The diagnostic's message.
189 public string message { get; set; }
192 public string category {
194 switch(this.severity) {
196 case DiagnosticSeverity.Error :
198 case DiagnosticSeverity.Warning :
199 return this.message.contains("deprecated") ? "DEPR" : "WARN";
210 * An event describing a change to a text document. If range and rangeLength are omitted
211 * the new text is considered to be the full content of the document.
213 public class TextDocumentContentChangeEvent : Object {
214 public Range? range { get; set; }
215 public int rangeLength { get; set; }
216 public string text { get; set; }
219 public enum MessageType {
229 * An information message.
238 public class TextDocumentIdentifier : Object {
239 public string uri { get; set; }
242 public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
244 * The version number of this document. If a versioned text document identifier
245 * is sent from the server to the client and the file is not open in the editor
246 * (the server has not received an open notification before) the server can send
247 * `null` to indicate that the version is known and the content on disk is the
248 * master (as speced with document content ownership).
250 * The version number of a document will increase after each change, including
251 * undo/redo. The number doesn't need to be consecutive.
253 public int version { get; set; default = -1; }
256 public class TextDocumentPositionParams : Object {
257 public TextDocumentIdentifier textDocument { get; set; }
258 public Position position { get; set; }
261 public class ReferenceParams : TextDocumentPositionParams {
262 public class ReferenceContext : Object {
263 public bool includeDeclaration { get; set; }
265 public ReferenceContext? context { get; set; }
268 public class Location : Object {
269 public string uri { get; set; }
270 public Range range { get; set; }
272 public Location.from_sourceref (Vala.SourceReference sref) {
273 this (sref.file.filename, new Range.from_sourceref (sref));
276 public Location (string filename, Range range) {
277 this.uri = File.new_for_commandline_arg (filename).get_uri ();
282 [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
283 public enum DocumentHighlightKind {
289 public class DocumentHighlight : Object {
290 public Range range { get; set; }
291 public DocumentHighlightKind kind { get; set; }
294 public class DocumentSymbolParams: Object {
295 public TextDocumentIdentifier textDocument { get; set; }
298 public class DocumentSymbol : Object, Json.Serializable {
299 private Vala.SourceReference? _source_reference;
300 public string name { get; set; }
301 public string? detail { get; set; }
302 public SymbolKind kind { get; set; }
303 public bool deprecated { get; set; }
304 private Range? _initial_range;
307 if (_initial_range == null)
308 _initial_range = new Range.from_sourceref (children.first ()._source_reference);
310 return children.fold<Range> ((child, current_range) => current_range.union (child.range), _initial_range);
313 public Range selectionRange { get; set; }
314 public Gee.List<DocumentSymbol> children { get; private set; default = new Gee.LinkedList<DocumentSymbol> (); }
315 public string? parent_name;
317 private DocumentSymbol () {}
320 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
321 * @param sym the symbol
324 public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
325 this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
326 this._initial_range = new Range.from_sourceref (sym.source_reference);
327 if (sym is Vala.Subroutine) {
328 var sub = (Vala.Subroutine) sym;
329 var body_sref = sub.body != null ? sub.body.source_reference : null;
330 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
331 // body_sref != null ? body_sref.to_string () : null);
332 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
333 body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
334 this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
337 this.name = sym.name;
338 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
340 this.selectionRange = new Range.from_sourceref (sym.source_reference);
341 this.deprecated = sym.version.deprecated;
344 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
345 base.set_property (pspec.get_name (), value);
348 public new Value Json.Serializable.get_property (ParamSpec pspec) {
349 Value val = Value (pspec.value_type);
350 base.get_property (pspec.get_name (), ref val);
354 public unowned ParamSpec? find_property (string name) {
355 return this.get_class ().find_property (name);
358 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
359 if (property_name != "children")
360 return default_serialize_property (property_name, value, pspec);
361 var node = new Json.Node (Json.NodeType.ARRAY);
362 node.init_array (new Json.Array ());
363 var array = node.get_array ();
364 foreach (var child in children)
365 array.add_element (Json.gobject_serialize (child));
369 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
370 error ("deserialization not supported");
374 public class SymbolInformation : Object {
375 public string name { get; set; }
376 public SymbolKind kind { get; set; }
377 public Location location { get; set; }
378 public string? containerName { get; set; }
380 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
381 this.name = dsym.name;
382 this.kind = dsym.kind;
383 this.location = new Location (uri, dsym.range);
384 this.containerName = dsym.parent_name;
388 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
389 public enum SymbolKind {
418 public class CompletionList : Object, Json.Serializable {
419 public bool isIncomplete { get; set; }
420 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
422 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
423 base.set_property (pspec.get_name (), value);
426 public new Value Json.Serializable.get_property (ParamSpec pspec) {
427 Value val = Value(pspec.value_type);
428 base.get_property (pspec.get_name (), ref val);
432 public unowned ParamSpec? find_property (string name) {
433 return this.get_class ().find_property (name);
436 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
437 if (property_name != "items")
438 return default_serialize_property (property_name, value, pspec);
439 var node = new Json.Node (Json.NodeType.ARRAY);
440 node.init_array (new Json.Array ());
441 var array = node.get_array ();
442 foreach (var child in items)
443 array.add_element (Json.gobject_serialize (child));
447 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
448 error ("deserialization not supported");
452 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
453 public enum CompletionTriggerKind {
455 * Completion was triggered by typing an identifier (24x7 code
456 * complete), manual invocation (e.g Ctrl+Space) or via API.
461 * Completion was triggered by a trigger character specified by
462 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
464 TriggerCharacter = 2,
467 * Completion was re-triggered as the current completion list is incomplete.
469 TriggerForIncompleteCompletions = 3
472 public class CompletionContext : Object {
473 public CompletionTriggerKind triggerKind { get; set;}
474 public string? triggerCharacter { get; set; }
477 public class CompletionParams : TextDocumentPositionParams {
479 * The completion context. This is only available if the client specifies
480 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
482 public CompletionContext? context { get; set; }
485 public enum CompletionItemTag {
486 // Render a completion as obsolete, usually using a strike-out.
490 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
491 public enum InsertTextFormat {
493 * The primary text to be inserted is treated as a plain string.
498 * The primary text to be inserted is treated as a snippet.
500 * A snippet can define tab stops and placeholders with `$1`, `$2`
501 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
502 * the end of the snippet. Placeholders with equal identifiers are linked,
503 * that is typing in one will update others too.
508 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
509 public string label { get; set; }
510 public CompletionItemKind kind { get; set; }
511 public string detail { get; set; }
512 public MarkupContent? documentation { get; set; }
513 public bool deprecated { get; set; }
514 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
515 public string? insertText { get; set; }
516 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
519 private CompletionItem () {}
521 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
522 this.label = keyword;
523 this.kind = CompletionItemKind.Keyword;
524 this.insertText = insert_text;
525 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
526 this.insertTextFormat = InsertTextFormat.Snippet;
527 if (documentation != null)
528 this.documentation = new MarkupContent.from_plaintext (documentation);
529 this._hash = @"$label $kind".hash ();
533 * A completion suggestion from an existing Vala symbol.
535 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
536 * @param sym the symbol itself
537 * @param scope the scope to display this in
538 * @param kind the kind of completion to display
539 * @param documentation the documentation to display
540 * @param label_override if non-null, override the displayed symbol name with this
543 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
544 CompletionItemKind kind,
545 Vls.DocComment? documentation, string? label_override = null) {
546 this.label = label_override ?? sym.name;
548 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
549 this._hash = @"$label $kind".hash ();
551 if (documentation != null)
552 this.documentation = new MarkupContent.from_markdown (documentation.body);
554 var version = sym.get_attribute ("Version");
555 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
556 this.tags.add (CompletionItemTag.Deprecated);
557 this.deprecated = true;
562 * A completion suggestion from a data type and a synthetic symbol name.
564 * @param symbol_type the data type of the symbol
565 * @param symbol_name the name of the synthetic symbol
566 * @param scope the scope that this completion item is displayed in, or null
567 * @param kind the type of completion to display
568 * @param documentation the documentation for this symbol, or null
571 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
572 CompletionItemKind kind, Vls.DocComment? documentation) {
573 this.label = symbol_name;
575 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
576 this._hash = @"$label $kind".hash ();
578 if (documentation != null)
579 this.documentation = new MarkupContent.from_markdown (documentation.body);
583 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
584 string label, CompletionItemKind kind,
586 Vls.DocComment? documentation) {
589 this.insertText = insert_text;
590 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
591 this.insertTextFormat = InsertTextFormat.Snippet;
592 this._hash = @"$label $kind".hash ();
593 if (documentation != null)
594 this.documentation = new MarkupContent.from_markdown (documentation.body);
598 public uint hash () {
602 public bool equal_to (CompletionItem other) {
603 return other.label == this.label && other.kind == this.kind;
606 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
607 base.set_property (pspec.get_name (), value);
610 public new Value Json.Serializable.get_property (ParamSpec pspec) {
611 Value val = Value(pspec.value_type);
612 base.get_property (pspec.get_name (), ref val);
616 public unowned ParamSpec? find_property (string name) {
617 return this.get_class ().find_property (name);
620 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
621 if (property_name != "tags")
622 return default_serialize_property (property_name, value, pspec);
624 var node = new Json.Node (Json.NodeType.ARRAY);
625 node.init_array (new Json.Array ());
626 var array = node.get_array ();
627 foreach (var tag in this.tags) {
628 array.add_int_element (tag);
633 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
635 if (property_name != "tags") {
636 return default_deserialize_property (property_name, out value, pspec, property_node);
638 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
639 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
643 var arguments = new Gee.ArrayList<CompletionItemTag>();
645 property_node.get_array ().foreach_element ((array, index, element) => {
647 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
649 warning ("argument %u to command could not be deserialized: %s", index, e.message);
653 value.set_boxed (arguments);
658 public class MarkupContent : Object {
659 public string kind { get; set; }
660 public string value { get; set; }
662 private MarkupContent () {}
665 * Create a MarkupContent with plain text.
667 public MarkupContent.from_plaintext (string doc) {
668 this.kind = "plaintext";
673 * Create a MarkupContent with markdown text.
675 public MarkupContent.from_markdown (string doc) {
676 this.kind = "markdown";
681 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
682 public enum CompletionItemKind {
711 * Capabilities of the client/editor for `textDocument/documentSymbol`
713 public class DocumentSymbolCapabilities : Object {
714 public bool hierarchicalDocumentSymbolSupport { get; set; }
718 * Capabilities of the client/editor for `textDocument/rename`
720 public class RenameClientCapabilities : Object {
721 public bool prepareSupport { get; set; }
725 * Capabilities of the client/editor pertaining to language features.
727 public class TextDocumentClientCapabilities : Object {
728 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
729 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
733 * Capabilities of the client/editor.
735 public class ClientCapabilities : Object {
736 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
739 public class InitializeParams : Object {
740 public int processId { get; set; }
741 public string? rootPath { get; set; }
742 public string? rootUri { get; set; }
743 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
746 public class SignatureInformation : Object, Json.Serializable {
747 public string label { get; set; }
748 public MarkupContent documentation { get; set; }
750 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
752 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
753 base.set_property (pspec.get_name (), value);
756 public new Value Json.Serializable.get_property (ParamSpec pspec) {
757 Value val = Value(pspec.value_type);
758 base.get_property (pspec.get_name (), ref val);
762 public unowned ParamSpec? find_property (string name) {
763 return this.get_class ().find_property (name);
766 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
767 if (property_name != "parameters")
768 return default_serialize_property (property_name, value, pspec);
769 var node = new Json.Node (Json.NodeType.ARRAY);
770 node.init_array (new Json.Array ());
771 var array = node.get_array ();
772 foreach (var child in parameters)
773 array.add_element (Json.gobject_serialize (child));
777 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
778 error ("deserialization not supported");
782 public class SignatureHelp : Object, Json.Serializable {
783 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
784 public int activeSignature { get; set; }
785 public int activeParameter { get; set; }
787 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
788 if (property_name != "signatures")
789 return default_serialize_property (property_name, value, pspec);
791 var node = new Json.Node (Json.NodeType.ARRAY);
792 node.init_array (new Json.Array ());
793 var array = node.get_array ();
794 foreach (var child in signatures)
795 array.add_element (Json.gobject_serialize (child));
799 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
800 error ("deserialization not supported");
804 public class ParameterInformation : Object {
805 public string label { get; set; }
806 public MarkupContent documentation { get; set; }
809 public class MarkedString : Object {
810 public string language { get; set; }
811 public string value { get; set; }
814 public class Hover : Object, Json.Serializable {
815 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
816 public Range range { get; set; }
818 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
819 base.set_property (pspec.get_name (), value);
822 public new Value Json.Serializable.get_property (ParamSpec pspec) {
823 Value val = Value(pspec.value_type);
824 base.get_property (pspec.get_name (), ref val);
828 public unowned ParamSpec? find_property (string name) {
829 return this.get_class ().find_property (name);
832 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
833 if (property_name != "contents")
834 return default_serialize_property (property_name, value, pspec);
835 var node = new Json.Node (Json.NodeType.ARRAY);
836 node.init_array (new Json.Array ());
837 var array = node.get_array ();
838 foreach (var child in contents) {
839 if (child.language != null)
840 array.add_element (Json.gobject_serialize (child));
842 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
847 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
848 error ("deserialization not supported");
853 * A textual edit applicable to a text document.
855 public class TextEdit : Object {
857 * The range of the text document to be manipulated. To insert
858 * text into a document create a range where ``start === end``.
860 public Range range { get; set; }
863 * The string to be inserted. For delete operations use an
866 public string newText { get; set; }
868 public TextEdit (Range range, string new_text = "") {
870 this.newText = new_text;
875 * Describes textual changes on a single text document. The text document is
876 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
877 * check the text document version before an edit is applied. A
878 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
879 * applied move the document to version ``Si+1``. So the creator of a
880 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
881 * of ordering. However the edits must be non overlapping.
883 public class TextDocumentEdit : Object, Json.Serializable {
885 * The text document to change.
887 public VersionedTextDocumentIdentifier textDocument { get; set; }
890 * The edits to be applied.
892 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
894 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
895 this.textDocument = text_document;
898 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
899 if (property_name != "edits")
900 return default_serialize_property (property_name, value, pspec);
902 var node = new Json.Node (Json.NodeType.ARRAY);
903 node.init_array (new Json.Array ());
904 var array = node.get_array ();
905 foreach (var text_edit in edits) {
906 array.add_element (Json.gobject_serialize (text_edit));
911 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
912 error ("deserialization not supported");
916 public abstract class CommandLike : Object, Json.Serializable {
918 * The identifier of the actual command handler.
920 public string command { get; set; }
923 * Arguments that the command handler should be invoked with.
925 public Array<Variant>? arguments { get; set; }
927 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
928 if (property_name != "arguments" || arguments == null)
929 return default_serialize_property (property_name, value, pspec);
931 var array = new Json.Array ();
932 for (int i = 0; i < arguments.length; i++)
933 array.add_element (Json.gvariant_serialize (arguments.index (i)));
935 var node = new Json.Node (Json.NodeType.ARRAY);
936 node.set_array (array);
940 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
941 if (property_name == "arguments") {
942 value = Value (typeof (Array));
943 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
944 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
948 var arguments = new Array<Variant> ();
950 property_node.get_array ().foreach_element ((array, index, element) => {
952 arguments.append_val (Json.gvariant_deserialize (element, null));
954 warning ("argument %u to command could not be deserialized: %s", index, e.message);
958 value.set_boxed (arguments);
960 } else if (property_name == "command") {
961 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
962 if (property_node.get_value_type () != typeof (string)) {
964 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
968 value = property_node.get_string ();
971 return default_deserialize_property (property_name, out value, pspec, property_node);
976 public class ExecuteCommandParams : CommandLike {
980 * Represents a reference to a command. Provides a title which will be used
981 * to represent a command in the UI. Commands are identified by a string
982 * identifier. The recommended way to handle commands is to implement their
983 * execution on the server side if the client and server provides the
984 * corresponding capabilities. Alternatively the tool extension code could
985 * handle the command. The protocol currently doesn’t specify a set of
986 * well-known commands.
988 public class Command : CommandLike {
990 * The title of the command, like `save`.
992 public string title { get; set; }
996 * A code lens represents a command that should be shown along with
997 * source text, like the number of references, a way to run tests, etc.
999 * A code lens is _unresolved_ when no command is associated to it. For
1000 * performance reasons the creation of a code lens and resolving should be done
1003 public class CodeLens : Object {
1005 * The range in which this code lens is valid. Should only span a single
1008 public Range range { get; set; }
1011 * The command this code lens represents.
1013 public Command? command { get; set; }
1016 public class DocumentRangeFormattingParams : Object {
1017 public TextDocumentIdentifier textDocument { get; set; }
1018 public Range? range { get; set; }
1019 public FormattingOptions options { get; set; }
1022 public class FormattingOptions : Object {
1023 public uint tabSize { get; set; }
1024 public bool insertSpaces { get; set; }
1025 public bool trimTrailingWhitespace { get; set; }
1026 public bool insertFinalNewline { get; set; }
1027 public bool trimFinalNewlines { get; set; }
1030 public class CodeActionParams : Object {
1031 public TextDocumentIdentifier textDocument { get; set; }
1032 public Range range { get; set; }
1033 public CodeActionContext context { get; set; }
1037 public class CodeActionContext : Object, Json.Serializable {
1038 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1039 public string[]? only { get; set; }
1041 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1042 if (property_name != "diagnostics")
1043 return default_deserialize_property (property_name, out value, pspec, property_node);
1044 var diags = new Gee.ArrayList<Diagnostic> ();
1045 property_node.get_array ().foreach_element ((array, index, element) => {
1047 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1049 warning ("argument %u could not be deserialized: %s", index, e.message);
1059 public class Diagnostics : Object, Json.Serializable
1061 public string uri { get; set; }
1063 public int version { get; set; default = 0; }
1064 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1066 public string filename {
1068 return File.new_for_uri (this.uri).get_path();
1073 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1074 if (property_name == "diagnostics") {
1075 var diags = new Gee.ArrayList<Diagnostic> ();
1076 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1078 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1084 property_node.get_array ().foreach_element ((array, index, element) => {
1086 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1088 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1096 return default_deserialize_property (property_name, out val, pspec, property_node);
1104 public class CodeAction : Object, Json.Serializable {
1105 public string title { get; set; }
1106 public string? kind { get; set; }
1107 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1108 public bool isPreferred { get; set; }
1109 public WorkspaceEdit? edit { get; set; }
1110 public Command? command { get; set; }
1111 public Object? data { get; set; }
1113 protected void add_diagnostic (Diagnostic diag) {
1114 if (diagnostics == null)
1115 diagnostics = new Gee.ArrayList<Diagnostic> ();
1116 diagnostics.add (diag);
1119 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1120 if (property_name != "diagnostics")
1121 return default_serialize_property (property_name, value, pspec);
1123 var array = new Json.Array ();
1124 if (diagnostics != null)
1125 foreach (var text_edit in diagnostics)
1126 array.add_element (Json.gobject_serialize (text_edit));
1127 return new Json.Node.alloc ().init_array (array);
1131 public class WorkspaceEdit : Object, Json.Serializable {
1132 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1134 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1135 if (property_name != "documentChanges")
1136 return default_serialize_property (property_name, value, pspec);
1138 var node = new Json.Node (Json.NodeType.ARRAY);
1139 node.init_array (new Json.Array ());
1140 if (documentChanges != null) {
1141 var array = node.get_array ();
1142 foreach (var text_edit in documentChanges) {
1143 array.add_element (Json.gobject_serialize (text_edit));
1151 public enum SymbolTags {
1156 public class CallHierarchyItem : Object, Json.Serializable {
1157 public string name { get; set; }
1158 public SymbolKind kind { get; set; }
1159 public SymbolTags tags { get; set; }
1160 public string? detail { get; set; }
1161 public string uri { get; set; }
1162 public Range range { get; set; }
1163 public Range selectionRange { get; set; }
1165 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1166 if (property_name != "tags")
1167 return default_serialize_property (property_name, value, pspec);
1168 var array = new Json.Array ();
1169 if (SymbolTags.DEPRECATED in tags)
1170 array.add_int_element (SymbolTags.DEPRECATED);
1171 return new Json.Node.alloc ().init_array (array);
1174 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1175 this.name = symbol.get_full_name ();
1176 if (symbol is Vala.Method) {
1177 if (symbol.parent_symbol is Vala.Namespace)
1178 this.kind = SymbolKind.Function;
1180 this.kind = SymbolKind.Method;
1181 } else if (symbol is Vala.Signal) {
1182 this.kind = SymbolKind.Event;
1183 } else if (symbol is Vala.Constructor) {
1184 this.kind = SymbolKind.Constructor;
1186 this.kind = SymbolKind.Method;
1188 var version = symbol.get_attribute ("Version");
1189 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1190 this.tags |= SymbolTags.DEPRECATED;
1192 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1193 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1194 this.range = new Range.from_sourceref (symbol.source_reference);
1195 if (symbol.comment != null)
1196 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1197 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1198 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1199 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1204 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1206 * The method that calls the query method.
1208 public CallHierarchyItem from { get; set; }
1211 * The ranges at which the query method is called by `from`.
1213 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1215 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1216 if (property_name == "from")
1217 return default_serialize_property (property_name, value, pspec);
1218 var array = new Json.Array ();
1219 foreach (var range in fromRanges)
1220 array.add_element (Json.gobject_serialize (range));
1221 return new Json.Node.alloc ().init_array (array);
1225 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1227 * The method that the query method calls.
1229 public CallHierarchyItem to { get; set; }
1232 * The ranges at which the method is called by the query method.
1234 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1236 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1237 if (property_name == "to")
1238 return default_serialize_property (property_name, value, pspec);
1239 var array = new Json.Array ();
1240 foreach (var range in fromRanges)
1241 array.add_element (Json.gobject_serialize (range));
1242 return new Json.Node.alloc ().init_array (array);
1246 public class InlayHintParams : Json.Serializable, Object {
1247 public TextDocumentIdentifier textDocument { get; set; }
1248 public Range range { get; set; }
1251 public enum InlayHintKind {
1257 public class InlayHint : Object {
1258 public Position position { get; set; }
1259 public string label { get; set; }
1260 public InlayHintKind kind { get; set; }
1261 public string? tooltip { get; set; }
1262 public bool paddingLeft { get; set; }
1263 public bool paddingRight { get; set; }
1266 public class TypeHierarchyItem : Object, Json.Serializable {
1268 * The name of this item
1270 public string name { get; set; }
1273 * The kind of this item
1275 public SymbolKind kind { get; set; }
1278 * Tags for this item
1280 public SymbolTags tags { get; set; }
1283 * More detail for this item, e.g. the signature of a function.
1285 public string? detail { get; set; }
1288 * The resource identifier of this item.
1290 public string uri { get; set; }
1293 * The range enclosing this symbol not including leading/trailing
1294 * whitespace, but everything else, e.g. comments and code.
1296 public Range range { get; set; }
1299 * The range that should be selected and revealed when this symbol
1300 * is being picked, e.g. the name of a function. Must be contained
1301 * by {@link TypeHierarchyItem.range}
1303 public Range selectionRange { get; set; }
1305 private TypeHierarchyItem () {}
1307 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1308 this.name = symbol.get_full_name ();
1309 if (symbol is Vala.Class)
1310 this.kind = SymbolKind.Class;
1311 else if (symbol is Vala.Delegate)
1312 this.kind = SymbolKind.Interface;
1313 else if (symbol is Vala.Enum)
1314 this.kind = SymbolKind.Enum;
1315 else if (symbol is Vala.ErrorCode)
1316 this.kind = SymbolKind.EnumMember;
1317 else if (symbol is Vala.ErrorDomain)
1318 this.kind = SymbolKind.Enum;
1319 else if (symbol is Vala.Interface)
1320 this.kind = SymbolKind.Interface;
1321 else if (symbol is Vala.Struct)
1322 this.kind = SymbolKind.Struct;
1323 else if (symbol is Vala.TypeParameter)
1324 this.kind = SymbolKind.TypeParameter;
1326 this.kind = SymbolKind.Module;
1327 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1330 var version = symbol.get_attribute ("Version");
1331 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1332 this.tags |= SymbolTags.DEPRECATED;
1334 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1335 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1336 this.range = new Range.from_sourceref (symbol.source_reference);
1337 this.selectionRange = this.range;
1339 // widen range to include all members
1340 if (symbol is Vala.ObjectTypeSymbol) {
1341 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1342 if (member.source_reference != null)
1343 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1345 } else if (symbol is Vala.Enum) {
1346 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1347 if (member.source_reference != null)
1348 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1350 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1351 if (method.source_reference != null)
1352 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1354 } else if (symbol is Vala.ErrorDomain) {
1355 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1356 if (member.source_reference != null)
1357 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1359 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1360 if (method.source_reference != null)
1361 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1363 } else if (symbol is Vala.Struct) {
1364 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1365 if (field.source_reference != null)
1366 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1368 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1369 if (method.source_reference != null)
1370 this.range = this.range.union (new Range.from_sourceref (method.source_reference));