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.new_line(uint line)
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) {
87 return line > other.line ? 1 :
89 (character > other.character ? 1 :
90 (character == other.character ? 0 : -1)) : -1);
92 public bool equals(Position o) {
93 return o.line == this.line && o.character == this.character;
96 public string to_string () {
97 return @"$line:$character";
100 public Position.from_libvala (Vala.SourceLocation sloc) {
101 line = sloc.line - 1;
102 character = sloc.column;
105 public Position dup () {
106 return this.translate ();
109 public Position translate (int dl = 0, int dc = 0) {
110 return new Position () {
111 line = this.line + dl,
112 character = this.character + dc
117 public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
119 public Range.simple(uint line, uint pos) {
120 var p = new Position () {
129 * The range's start position.
131 public Position start { get; set; }
134 * The range's end position.
136 public Position end { get; set; }
138 private string? filename;
140 public string to_string () { return (filename != null ? @"$filename:" : "") + @"$start -> $end"; }
142 public Range.from_pos (Position pos) {
144 this.end = pos.dup ();
147 public Range.from_sourceref (Vala.SourceReference sref) {
148 this.start = new Position.from_libvala (sref.begin);
149 this.end = new Position.from_libvala (sref.end);
150 this.start.character -= 1;
151 this.filename = sref.file.filename;
154 public uint hash () {
155 return this.to_string ().hash ();
158 public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
159 public bool equals (Range o) {
160 return this.filename == o.filename && this.start.equals(o.start) && this.end.equals(o.end);
163 public int compare_to (Range other) {
164 return start.compare_to (other.start);
168 * Return a new range that includes `this` and `other`.
170 public Range union (Range other) {
171 var range = new Range () {
172 start = start.compare_to (other.start) < 0 ? start : other.start,
173 end = end.compare_to (other.end) < 0 ? other.end : end,
175 if (filename == other.filename)
176 range.filename = filename;
180 public bool contains (Position pos) {
181 GLib.debug( "range contains %d (%d-%d)", (int)pos.line, (int)start.line, (int)end.line);
182 var ret = start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
187 public class Diagnostic : Object {
189 public Diagnostic.simple ( int line, int character, string message)
191 this.message = message;
192 this.severity = DiagnosticSeverity.Error;
193 this.range = new Range.simple(line, character );
199 * The range at which the message applies.
201 public Range range { get; set; }
204 * The diagnostic's severity. Can be omitted. If omitted it is up to the
205 * client to interpret diagnostics as error, warning, info or hint.
207 public DiagnosticSeverity severity { get; set; }
210 * The diagnostic's code. Can be omitted.
212 public string? code { get; set; }
215 * A human-readable string describing the source of this
216 * diagnostic, e.g. 'typescript' or 'super lint'.
218 public string? source { get; set; }
221 * The diagnostic's message.
223 public string message { get; set; }
226 public string category {
228 switch(this.severity) {
230 case DiagnosticSeverity.Error :
232 case DiagnosticSeverity.Warning :
233 return this.message.contains("deprecated") ? "DEPR" : "WARN";
241 public bool equals(Lsp.Diagnostic o) {
242 var ret = this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
243 //GLib.debug("compare %s (%s == %s)", ret ? "YES" : "NO", this.to_string(), o.to_string());
248 public string to_string()
250 return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
256 * An event describing a change to a text document. If range and rangeLength are omitted
257 * the new text is considered to be the full content of the document.
259 public class TextDocumentContentChangeEvent : Object {
260 public Range? range { get; set; }
261 public int rangeLength { get; set; }
262 public string text { get; set; }
265 public enum MessageType {
275 * An information message.
284 public class TextDocumentIdentifier : Object {
285 public string uri { get; set; }
288 public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
290 * The version number of this document. If a versioned text document identifier
291 * is sent from the server to the client and the file is not open in the editor
292 * (the server has not received an open notification before) the server can send
293 * `null` to indicate that the version is known and the content on disk is the
294 * master (as speced with document content ownership).
296 * The version number of a document will increase after each change, including
297 * undo/redo. The number doesn't need to be consecutive.
299 public int version { get; set; default = -1; }
302 public class TextDocumentPositionParams : Object {
303 public TextDocumentIdentifier textDocument { get; set; }
304 public Position position { get; set; }
307 public class ReferenceParams : TextDocumentPositionParams {
308 public class ReferenceContext : Object {
309 public bool includeDeclaration { get; set; }
311 public ReferenceContext? context { get; set; }
314 public class Location : Object {
315 public string uri { get; set; }
316 public Range range { get; set; }
318 public Location.from_sourceref (Vala.SourceReference sref) {
319 this (sref.file.filename, new Range.from_sourceref (sref));
322 public Location (string filename, Range range) {
323 this.uri = File.new_for_commandline_arg (filename).get_uri ();
328 [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
329 public enum DocumentHighlightKind {
335 public class DocumentHighlight : Object {
336 public Range range { get; set; }
337 public DocumentHighlightKind kind { get; set; }
340 public class DocumentSymbolParams: Object {
341 public TextDocumentIdentifier textDocument { get; set; }
344 public class DocumentSymbol : Object, Json.Serializable {
345 private Vala.SourceReference? _source_reference;
346 public string name { get; set; }
347 public string detail { get; set; default = ""; }
348 public SymbolKind kind { get; set; }
349 public bool deprecated { get; set; }
351 public Range range { get; set; }
352 public Range selectionRange { get; set; }
353 public GLib.ListStore children { get; set; default = new GLib.ListStore(typeof(DocumentSymbol)); }
354 public string? parent_name;
356 private DocumentSymbol () {}
359 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
360 * @param sym the symbol
363 public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
364 this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
365 this._initial_range = new Range.from_sourceref (sym.source_reference);
366 if (sym is Vala.Subroutine) {
367 var sub = (Vala.Subroutine) sym;
368 var body_sref = sub.body != null ? sub.body.source_reference : null;
369 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
370 // body_sref != null ? body_sref.to_string () : null);
371 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
372 val = GLib.Value (typeof(Gee.ArrayList)); body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
373 this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
376 this.name = sym.name;
377 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
379 this.selectionRange = new Range.from_sourceref (sym.source_reference);
380 this.deprecated = sym.version.deprecated;
383 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
384 base.set_property (pspec.get_name (), value);
387 public new Value Json.Serializable.get_property (ParamSpec pspec) {
388 Value val = Value (pspec.value_type);
389 base.get_property (pspec.get_name (), ref val);
393 public unowned ParamSpec? find_property (string name) {
394 return this.get_class ().find_property (name);
397 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
398 // if (property_name != "children")
399 return default_serialize_property (property_name, value, pspec);
400 /*var node = new Json.Node (Json.NodeType.ARRAY);
401 node.init_array (new Json.Array ());
402 var array = node.get_array ();
403 foreach (var child in children)
404 array.add_element (Json.gobject_serialize (child));
409 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
411 GLib.debug("deserialise property %s" , property_name);
412 if (property_name != "children") {
413 return default_deserialize_property (property_name, out value, pspec, property_node);
415 value = GLib.Value (typeof(GLib.ListStore));
416 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
417 GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
420 GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
421 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
423 property_node.get_array ().foreach_element ((array, index, element) => {
425 var add= Json.gobject_deserialize ( typeof (DocumentSymbol), array.get_element(index)) as DocumentSymbol;
426 arguments.append( add);
431 value.set_object (arguments);
434 public string symbol_icon {
437 return this.kind.icon();
441 public string tooltip {
443 GLib.debug("%s : %s", this.name, this.detail);
444 //var detail = this.detail == "" ? (this.kind.to_string() + ": " + this.name) : this.detail;
445 return 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(int line)
457 if (!this.range.contains(new Position.new_line(line))) {
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);
471 public bool equals(DocumentSymbol sym) {
472 return this.name == sym.name && this.kind == sym.kind && sym.range.equals(this.range);
478 public class SymbolInformation : Object {
479 public string name { get; set; }
480 public SymbolKind kind { get; set; }
481 public Location location { get; set; }
482 public string? containerName { get; set; }
484 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
485 this.name = dsym.name;
486 this.kind = dsym.kind;
487 // this.location = new Location (uri, dsym.range);
488 this.containerName = dsym.parent_name;
492 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
493 public enum SymbolKind {
521 public string icon () {
525 // case SymbolKind.Text: return "completion-snippet-symbolic";
526 case SymbolKind.Method: return "lang-method-symbolic";
527 case SymbolKind.Function: return "lang-function-symbolic";
528 case SymbolKind.Constructor: return "lang-method-symbolic";
529 case SymbolKind.Field: return "lang-struct-field-symbolic";
530 case SymbolKind.Variable: return "lang-variable-symbolic";
531 case SymbolKind.Class: return "lang-class-symbolic";
532 case SymbolKind.Interface: return "lang-class-symbolic";
533 case SymbolKind.Module: return "lang-namespace-symbolic";
534 case SymbolKind.Property:return "lang-struct-field-symbolic";
535 //case SymbolKind.Unit: return "lang-variable-symbolic";
536 //case SymbolKind.Value: return "lang-variable-symbolic";
537 case SymbolKind.Enum: return "lang-enum-symbolic";
538 //case SymbolKind.Keyword: return "completion-word-symbolic";
539 //case SymbolKind.Snippet: return "completion-snippet-symbolic";
541 //case SymbolKind.Color: return "lang-typedef-symbolic";
542 case SymbolKind.File:return "lang-typedef-symbolic";
543 //case SymbolKind.Reference: return "lang-typedef-symbolic";
544 //case SymbolKind.Folder:return "lang-typedef-symbolic";
545 case SymbolKind.EnumMember: return "lang-typedef-symbolic";
546 case SymbolKind.Constant:return "lang-typedef-symbolic";
547 case SymbolKind.Struct: return "lang-struct-symbolic";
548 case SymbolKind.Event:return "lang-typedef-symbolic";
549 case SymbolKind.Operator:return "lang-typedef-symbolic";
550 case SymbolKind.TypeParameter:return "lang-typedef-symbolic";
553 return "completion-snippet-symbolic";
557 public int sort_key() {
560 case Enum : return 1;
561 case Class: return 2;
563 case Constructor : return 1;
564 case Method : return 2;
565 case Field : return 3;
566 case Property : return 3;
578 public class CompletionList : Object, Json.Serializable {
579 public bool isIncomplete { get; set; }
580 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
582 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
583 base.set_property (pspec.get_name (), value);
586 public new Value Json.Serializable.get_property (ParamSpec pspec) {
587 Value val = Value(pspec.value_type);
588 base.get_property (pspec.get_name (), ref val);
592 public unowned ParamSpec? find_property (string name) {
593 return this.get_class ().find_property (name);
596 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
597 if (property_name != "items")
598 return default_serialize_property (property_name, value, pspec);
599 var node = new Json.Node (Json.NodeType.ARRAY);
600 node.init_array (new Json.Array ());
601 var array = node.get_array ();
602 foreach (var child in items)
603 array.add_element (Json.gobject_serialize (child));
607 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
608 error ("deserialization not supported");
612 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
613 public enum CompletionTriggerKind {
615 * Completion was triggered by typing an identifier (24x7 code
616 * complete), manual invocation (e.g Ctrl+Space) or via API.
621 * Completion was triggered by a trigger character specified by
622 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
624 TriggerCharacter = 2,
627 * Completion was re-triggered as the current completion list is incomplete.
629 TriggerForIncompleteCompletions = 3
632 public class CompletionContext : Object {
633 public CompletionTriggerKind triggerKind { get; set;}
634 public string? triggerCharacter { get; set; }
637 public class CompletionParams : TextDocumentPositionParams {
639 * The completion context. This is only available if the client specifies
640 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
642 public CompletionContext? context { get; set; }
645 public enum CompletionItemTag {
646 // Render a completion as obsolete, usually using a strike-out.
650 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
651 public enum InsertTextFormat {
653 * The primary text to be inserted is treated as a plain string.
658 * The primary text to be inserted is treated as a snippet.
660 * A snippet can define tab stops and placeholders with `$1`, `$2`
661 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
662 * the end of the snippet. Placeholders with equal identifiers are linked,
663 * that is typing in one will update others too.
668 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
669 public string label { get; set; }
670 public CompletionItemKind kind { get; set; }
671 public string detail { get; set; }
672 public MarkupContent? documentation { get; set; }
673 public bool deprecated { get; set; }
674 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
675 public string? insertText { get; set; }
676 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
679 private CompletionItem () {}
681 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
682 this.label = keyword;
683 this.kind = CompletionItemKind.Keyword;
684 this.insertText = insert_text;
685 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
686 this.insertTextFormat = InsertTextFormat.Snippet;
687 if (documentation != null)
688 this.documentation = new MarkupContent.from_plaintext (documentation);
689 this._hash = @"$label $kind".hash ();
693 * A completion suggestion from an existing Vala symbol.
695 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
696 * @param sym the symbol itself
697 * @param scope the scope to display this in
698 * @param kind the kind of completion to display
699 * @param documentation the documentation to display
700 * @param label_override if non-null, override the displayed symbol name with this
703 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
704 CompletionItemKind kind,
705 Vls.DocComment? documentation, string? label_override = null) {
706 this.label = label_override ?? sym.name;
708 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
709 this._hash = @"$label $kind".hash ();
711 if (documentation != null)
712 this.documentation = new MarkupContent.from_markdown (documentation.body);
714 var version = sym.get_attribute ("Version");
715 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
716 this.tags.add (CompletionItemTag.Deprecated);
717 this.deprecated = true;
722 * A completion suggestion from a data type and a synthetic symbol name.
724 * @param symbol_type the data type of the symbol
725 * @param symbol_name the name of the synthetic symbol
726 * @param scope the scope that this completion item is displayed in, or null
727 * @param kind the type of completion to display
728 * @param documentation the documentation for this symbol, or null
731 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
732 CompletionItemKind kind, Vls.DocComment? documentation) {
733 this.label = symbol_name;
735 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
736 this._hash = @"$label $kind".hash ();
738 if (documentation != null)
739 this.documentation = new MarkupContent.from_markdown (documentation.body);
743 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
744 string label, CompletionItemKind kind,
746 Vls.DocComment? documentation) {
749 this.insertText = insert_text;
750 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
751 this.insertTextFormat = InsertTextFormat.Snippet;
752 this._hash = @"$label $kind".hash ();
753 if (documentation != null)
754 this.documentation = new MarkupContent.from_markdown (documentation.body);
758 public uint hash () {
762 public bool equal_to (CompletionItem other) {
763 return other.label == this.label && other.kind == this.kind;
766 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
767 base.set_property (pspec.get_name (), value);
770 public new Value Json.Serializable.get_property (ParamSpec pspec) {
771 Value val = Value(pspec.value_type);
772 base.get_property (pspec.get_name (), ref val);
776 public unowned ParamSpec? find_property (string name) {
777 return this.get_class ().find_property (name);
780 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
781 if (property_name != "tags")
782 return default_serialize_property (property_name, value, pspec);
784 var node = new Json.Node (Json.NodeType.ARRAY);
785 node.init_array (new Json.Array ());
786 var array = node.get_array ();
787 foreach (var tag in this.tags) {
788 array.add_int_element (tag);
793 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
795 if (property_name != "tags") {
796 return default_deserialize_property (property_name, out value, pspec, property_node);
798 value = GLib.Value (typeof(Gee.ArrayList));
799 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
800 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
804 var arguments = new Gee.ArrayList<CompletionItemTag>();
806 property_node.get_array ().foreach_element ((array, index, element) => {
808 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
810 warning ("argument %u to command could not be deserialized: %s", index, e.message);
814 value.set_object (arguments);
819 public class MarkupContent : Object {
820 public string kind { get; set; }
821 public string value { get; set; }
823 private MarkupContent () {}
826 * Create a MarkupContent with plain text.
828 public MarkupContent.from_plaintext (string doc) {
829 this.kind = "plaintext";
834 * Create a MarkupContent with markdown text.
836 public MarkupContent.from_markdown (string doc) {
837 this.kind = "markdown";
842 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
843 public enum CompletionItemKind {
872 * Capabilities of the client/editor for `textDocument/documentSymbol`
874 public class DocumentSymbolCapabilities : Object {
875 public bool hierarchicalDocumentSymbolSupport { get; set; }
879 * Capabilities of the client/editor for `textDocument/rename`
881 public class RenameClientCapabilities : Object {
882 public bool prepareSupport { get; set; }
886 * Capabilities of the client/editor pertaining to language features.
888 public class TextDocumentClientCapabilities : Object {
889 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
890 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
894 * Capabilities of the client/editor.
896 public class ClientCapabilities : Object {
897 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
900 public class InitializeParams : Object {
901 public int processId { get; set; }
902 public string? rootPath { get; set; }
903 public string? rootUri { get; set; }
904 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
907 public class SignatureInformation : Object, Json.Serializable {
908 public string label { get; set; }
909 public MarkupContent documentation { get; set; }
911 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
913 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
914 base.set_property (pspec.get_name (), value);
917 public new Value Json.Serializable.get_property (ParamSpec pspec) {
918 Value val = Value(pspec.value_type);
919 base.get_property (pspec.get_name (), ref val);
923 public unowned ParamSpec? find_property (string name) {
924 return this.get_class ().find_property (name);
927 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
928 if (property_name != "parameters")
929 return default_serialize_property (property_name, value, pspec);
930 var node = new Json.Node (Json.NodeType.ARRAY);
931 node.init_array (new Json.Array ());
932 var array = node.get_array ();
933 foreach (var child in parameters)
934 array.add_element (Json.gobject_serialize (child));
938 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
939 error ("deserialization not supported");
943 public class SignatureHelp : Object, Json.Serializable {
944 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
945 public int activeSignature { get; set; }
946 public int activeParameter { get; set; }
948 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
949 if (property_name != "signatures")
950 return default_serialize_property (property_name, value, pspec);
952 var node = new Json.Node (Json.NodeType.ARRAY);
953 node.init_array (new Json.Array ());
954 var array = node.get_array ();
955 foreach (var child in signatures)
956 array.add_element (Json.gobject_serialize (child));
960 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
961 error ("deserialization not supported");
965 public class ParameterInformation : Object {
966 public string label { get; set; }
967 public MarkupContent documentation { get; set; }
970 public class MarkedString : Object {
971 public MarkedString(string language, string value)
973 this.language = language;
975 GLib.debug("new marked string %s : %s", language, value);
977 public string language { get; set; }
978 public string value { get; set; }
981 public class Hover : Object, Json.Serializable {
982 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
983 public Range range { get; set; }
985 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
986 base.set_property (pspec.get_name (), value);
989 public new Value Json.Serializable.get_property (ParamSpec pspec) {
990 Value val = Value(pspec.value_type);
991 base.get_property (pspec.get_name (), ref val);
995 public unowned ParamSpec? find_property (string name) {
996 return this.get_class ().find_property (name);
999 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
1000 if (property_name != "contents")
1001 return default_serialize_property (property_name, value, pspec);
1002 var node = new Json.Node (Json.NodeType.ARRAY);
1003 node.init_array (new Json.Array ());
1004 var array = node.get_array ();
1005 foreach (var child in contents) {
1006 if (child.language != null)
1007 array.add_element (Json.gobject_serialize (child));
1009 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
1014 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
1016 if (property_name == "contents") {
1017 value = GLib.Value (typeof(Gee.ArrayList));
1018 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1019 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1022 var contents = new Gee.ArrayList<MarkedString>();
1024 property_node.get_array ().foreach_element ((array, index, element) => {
1026 var add = new MarkedString(
1027 array.get_object_element(index).get_string_member("language"),
1028 array.get_object_element(index).get_string_member("value")
1031 contents.add ( add );
1033 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1036 value.set_object (contents);
1040 return default_deserialize_property (property_name, out value, pspec, property_node);
1045 * A textual edit applicable to a text document.
1047 public class TextEdit : Object {
1049 * The range of the text document to be manipulated. To insert
1050 * text into a document create a range where ``start === end``.
1052 public Range range { get; set; }
1055 * The string to be inserted. For delete operations use an
1058 public string newText { get; set; }
1060 public TextEdit (Range range, string new_text = "") {
1062 this.newText = new_text;
1067 * Describes textual changes on a single text document. The text document is
1068 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
1069 * check the text document version before an edit is applied. A
1070 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
1071 * applied move the document to version ``Si+1``. So the creator of a
1072 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
1073 * of ordering. However the edits must be non overlapping.
1075 public class TextDocumentEdit : Object, Json.Serializable {
1077 * The text document to change.
1079 public VersionedTextDocumentIdentifier textDocument { get; set; }
1082 * The edits to be applied.
1084 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
1086 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
1087 this.textDocument = text_document;
1090 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1091 if (property_name != "edits")
1092 return default_serialize_property (property_name, value, pspec);
1094 var node = new Json.Node (Json.NodeType.ARRAY);
1095 node.init_array (new Json.Array ());
1096 var array = node.get_array ();
1097 foreach (var text_edit in edits) {
1098 array.add_element (Json.gobject_serialize (text_edit));
1103 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1104 error ("deserialization not supported");
1108 public abstract class CommandLike : Object, Json.Serializable {
1110 * The identifier of the actual command handler.
1112 public string command { get; set; }
1115 * Arguments that the command handler should be invoked with.
1117 public Array<Variant>? arguments { get; set; }
1119 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1120 if (property_name != "arguments" || arguments == null)
1121 return default_serialize_property (property_name, value, pspec);
1123 var array = new Json.Array ();
1124 for (int i = 0; i < arguments.length; i++)
1125 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1127 var node = new Json.Node (Json.NodeType.ARRAY);
1128 node.set_array (array);
1132 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1134 if (property_name == "arguments") {
1135 value = GLib.Value (typeof(Array));
1136 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1137 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1141 var arguments = new Array<Variant> ();
1143 property_node.get_array ().foreach_element ((array, index, element) => {
1145 arguments.append_val (Json.gvariant_deserialize (element, null));
1147 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1151 value.set_boxed (arguments);
1153 } else if (property_name == "command") {
1154 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1155 if (property_node.get_value_type () != typeof (string)) {
1157 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1161 value = property_node.get_string ();
1164 return default_deserialize_property (property_name, out value, pspec, property_node);
1169 public class ExecuteCommandParams : CommandLike {
1173 * Represents a reference to a command. Provides a title which will be used
1174 * to represent a command in the UI. Commands are identified by a string
1175 * identifier. The recommended way to handle commands is to implement their
1176 * execution on the server side if the client and server provides the
1177 * corresponding capabilities. Alternatively the tool extension code could
1178 * handle the command. The protocol currently doesn’t specify a set of
1179 * well-known commands.
1181 public class Command : CommandLike {
1183 * The title of the command, like `save`.
1185 public string title { get; set; }
1189 * A code lens represents a command that should be shown along with
1190 * source text, like the number of references, a way to run tests, etc.
1192 * A code lens is _unresolved_ when no command is associated to it. For
1193 * performance reasons the creation of a code lens and resolving should be done
1196 public class CodeLens : Object {
1198 * The range in which this code lens is valid. Should only span a single
1201 public Range range { get; set; }
1204 * The command this code lens represents.
1206 public Command? command { get; set; }
1209 public class DocumentRangeFormattingParams : Object {
1210 public TextDocumentIdentifier textDocument { get; set; }
1211 public Range? range { get; set; }
1212 public FormattingOptions options { get; set; }
1215 public class FormattingOptions : Object {
1216 public uint tabSize { get; set; }
1217 public bool insertSpaces { get; set; }
1218 public bool trimTrailingWhitespace { get; set; }
1219 public bool insertFinalNewline { get; set; }
1220 public bool trimFinalNewlines { get; set; }
1223 public class CodeActionParams : Object {
1224 public TextDocumentIdentifier textDocument { get; set; }
1225 public Range range { get; set; }
1226 public CodeActionContext context { get; set; }
1230 public class CodeActionContext : Object, Json.Serializable {
1231 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1232 public string[]? only { get; set; }
1234 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1235 if (property_name != "diagnostics")
1236 return default_deserialize_property (property_name, out value, pspec, property_node);
1237 var diags = new Gee.ArrayList<Diagnostic> ();
1238 property_node.get_array ().foreach_element ((array, index, element) => {
1240 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1242 warning ("argument %u could not be deserialized: %s", index, e.message);
1252 public class Diagnostics : Object, Json.Serializable
1254 public Diagnostics()
1256 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1261 public string uri { get; set; }
1263 public int version { get; set; default = 0; }
1264 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1266 public string filename {
1268 return File.new_for_uri (this.uri).get_path();
1273 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1274 if (property_name == "diagnostics") {
1275 val = GLib.Value (typeof(Gee.ArrayList));
1276 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1279 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1280 val.set_object(diags);
1281 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1287 property_node.get_array ().foreach_element ((array, index, element) => {
1289 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1291 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1294 val.set_object(diags);
1299 return default_deserialize_property (property_name, out val, pspec, property_node);
1307 public class CodeAction : Object, Json.Serializable {
1308 public string title { get; set; }
1309 public string? kind { get; set; }
1310 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1311 public bool isPreferred { get; set; }
1312 public WorkspaceEdit? edit { get; set; }
1313 public Command? command { get; set; }
1314 public Object? data { get; set; }
1316 protected void add_diagnostic (Diagnostic diag) {
1317 if (diagnostics == null)
1318 diagnostics = new Gee.ArrayList<Diagnostic> ();
1319 diagnostics.add (diag);
1322 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1323 if (property_name != "diagnostics")
1324 return default_serialize_property (property_name, value, pspec);
1326 var array = new Json.Array ();
1327 if (diagnostics != null)
1328 foreach (var text_edit in diagnostics)
1329 array.add_element (Json.gobject_serialize (text_edit));
1330 return new Json.Node.alloc ().init_array (array);
1334 public class WorkspaceEdit : Object, Json.Serializable {
1335 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1337 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1338 if (property_name != "documentChanges")
1339 return default_serialize_property (property_name, value, pspec);
1341 var node = new Json.Node (Json.NodeType.ARRAY);
1342 node.init_array (new Json.Array ());
1343 if (documentChanges != null) {
1344 var array = node.get_array ();
1345 foreach (var text_edit in documentChanges) {
1346 array.add_element (Json.gobject_serialize (text_edit));
1354 public enum SymbolTags {
1359 public class CallHierarchyItem : Object, Json.Serializable {
1360 public string name { get; set; }
1361 public SymbolKind kind { get; set; }
1362 public SymbolTags tags { get; set; }
1363 public string? detail { get; set; }
1364 public string uri { get; set; }
1365 public Range range { get; set; }
1366 public Range selectionRange { get; set; }
1368 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1369 if (property_name != "tags")
1370 return default_serialize_property (property_name, value, pspec);
1371 var array = new Json.Array ();
1372 if (SymbolTags.DEPRECATED in tags)
1373 array.add_int_element (SymbolTags.DEPRECATED);
1374 return new Json.Node.alloc ().init_array (array);
1377 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1378 this.name = symbol.get_full_name ();
1379 if (symbol is Vala.Method) {
1380 if (symbol.parent_symbol is Vala.Namespace)
1381 this.kind = SymbolKind.Function;
1383 this.kind = SymbolKind.Method;
1384 } else if (symbol is Vala.Signal) {
1385 this.kind = SymbolKind.Event;
1386 } else if (symbol is Vala.Constructor) {
1387 this.kind = SymbolKind.Constructor;
1389 this.kind = SymbolKind.Method;
1391 var version = symbol.get_attribute ("Version");
1392 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1393 this.tags |= SymbolTags.DEPRECATED;
1395 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1396 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1397 this.range = new Range.from_sourceref (symbol.source_reference);
1398 if (symbol.comment != null)
1399 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1400 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1401 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1402 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1407 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1409 * The method that calls the query method.
1411 public CallHierarchyItem from { get; set; }
1414 * The ranges at which the query method is called by `from`.
1416 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1418 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1419 if (property_name == "from")
1420 return default_serialize_property (property_name, value, pspec);
1421 var array = new Json.Array ();
1422 foreach (var range in fromRanges)
1423 array.add_element (Json.gobject_serialize (range));
1424 return new Json.Node.alloc ().init_array (array);
1428 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1430 * The method that the query method calls.
1432 public CallHierarchyItem to { get; set; }
1435 * The ranges at which the method is called by the query method.
1437 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1439 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1440 if (property_name == "to")
1441 return default_serialize_property (property_name, value, pspec);
1442 var array = new Json.Array ();
1443 foreach (var range in fromRanges)
1444 array.add_element (Json.gobject_serialize (range));
1445 return new Json.Node.alloc ().init_array (array);
1449 public class InlayHintParams : Json.Serializable, Object {
1450 public TextDocumentIdentifier textDocument { get; set; }
1451 public Range range { get; set; }
1454 public enum InlayHintKind {
1460 public class InlayHint : Object {
1461 public Position position { get; set; }
1462 public string label { get; set; }
1463 public InlayHintKind kind { get; set; }
1464 public string? tooltip { get; set; }
1465 public bool paddingLeft { get; set; }
1466 public bool paddingRight { get; set; }
1469 public class TypeHierarchyItem : Object, Json.Serializable {
1471 * The name of this item
1473 public string name { get; set; }
1476 * The kind of this item
1478 public SymbolKind kind { get; set; }
1481 * Tags for this item
1483 public SymbolTags tags { get; set; }
1486 * More detail for this item, e.g. the signature of a function.
1488 public string? detail { get; set; }
1491 * The resource identifier of this item.
1493 public string uri { get; set; }
1496 * The range enclosing this symbol not including leading/trailing
1497 * whitespace, but everything else, e.g. comments and code.
1499 public Range range { get; set; }
1502 * The range that should be selected and revealed when this symbol
1503 * is being picked, e.g. the name of a function. Must be contained
1504 * by {@link TypeHierarchyItem.range}
1506 public Range selectionRange { get; set; }
1508 private TypeHierarchyItem () {}
1510 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1511 this.name = symbol.get_full_name ();
1512 if (symbol is Vala.Class)
1513 this.kind = SymbolKind.Class;
1514 else if (symbol is Vala.Delegate)
1515 this.kind = SymbolKind.Interface;
1516 else if (symbol is Vala.Enum)
1517 this.kind = SymbolKind.Enum;
1518 else if (symbol is Vala.ErrorCode)
1519 this.kind = SymbolKind.EnumMember;
1520 else if (symbol is Vala.ErrorDomain)
1521 this.kind = SymbolKind.Enum;
1522 else if (symbol is Vala.Interface)
1523 this.kind = SymbolKind.Interface;
1524 else if (symbol is Vala.Struct)
1525 this.kind = SymbolKind.Struct;
1526 else if (symbol is Vala.TypeParameter)
1527 this.kind = SymbolKind.TypeParameter;
1529 this.kind = SymbolKind.Module;
1530 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1533 var version = symbol.get_attribute ("Version");
1534 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1535 this.tags |= SymbolTags.DEPRECATED;
1537 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1538 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1539 this.range = new Range.from_sourceref (symbol.source_reference);
1540 this.selectionRange = this.range;
1542 // widen range to include all members
1543 if (symbol is Vala.ObjectTypeSymbol) {
1544 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1545 if (member.source_reference != null)
1546 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1548 } else if (symbol is Vala.Enum) {
1549 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1550 if (member.source_reference != null)
1551 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1553 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1554 if (method.source_reference != null)
1555 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1557 } else if (symbol is Vala.ErrorDomain) {
1558 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1559 if (member.source_reference != null)
1560 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1562 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1563 if (method.source_reference != null)
1564 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1566 } else if (symbol is Vala.Struct) {
1567 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1568 if (field.source_reference != null)
1569 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1571 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1572 if (method.source_reference != null)
1573 this.range = this.range.union (new Range.from_sourceref (method.source_reference));