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 && this.start.equals(o.start) && this.end.equals(o.end);
158 public int compare_to (Range other) {
159 return start.compare_to (other.start);
163 * Return a new range that includes `this` and `other`.
165 public Range union (Range other) {
166 var range = new Range () {
167 start = start.compare_to (other.start) < 0 ? start : other.start,
168 end = end.compare_to (other.end) < 0 ? other.end : end,
170 if (filename == other.filename)
171 range.filename = filename;
175 public bool contains (Position pos) {
177 var ret = start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
178 // GLib.debug( "range contains %d (%d-%d) %s", (int)pos.line, (int)start.line, (int)end.line, ret ? "Y" : "N");
184 public class Diagnostic : Object {
186 public Diagnostic.simple ( int line, int character, string message)
188 this.message = message;
189 this.severity = DiagnosticSeverity.Error;
190 this.range = new Range.simple(line, character );
196 * The range at which the message applies.
198 public Range range { get; set; }
201 * The diagnostic's severity. Can be omitted. If omitted it is up to the
202 * client to interpret diagnostics as error, warning, info or hint.
204 public DiagnosticSeverity severity { get; set; }
207 * The diagnostic's code. Can be omitted.
209 public string? code { get; set; }
212 * A human-readable string describing the source of this
213 * diagnostic, e.g. 'typescript' or 'super lint'.
215 public string? source { get; set; }
218 * The diagnostic's message.
220 public string message { get; set; }
223 public string category {
225 switch(this.severity) {
227 case DiagnosticSeverity.Error :
229 case DiagnosticSeverity.Warning :
230 return this.message.contains("deprecated") ? "DEPR" : "WARN";
238 public bool equals(Lsp.Diagnostic o) {
239 var ret = this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
240 //GLib.debug("compare %s (%s == %s)", ret ? "YES" : "NO", this.to_string(), o.to_string());
245 public string to_string()
247 return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
253 * An event describing a change to a text document. If range and rangeLength are omitted
254 * the new text is considered to be the full content of the document.
256 public class TextDocumentContentChangeEvent : Object {
257 public Range? range { get; set; }
258 public int rangeLength { get; set; }
259 public string text { get; set; }
262 public enum MessageType {
272 * An information message.
281 public class TextDocumentIdentifier : Object {
282 public string uri { get; set; }
285 public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
287 * The version number of this document. If a versioned text document identifier
288 * is sent from the server to the client and the file is not open in the editor
289 * (the server has not received an open notification before) the server can send
290 * `null` to indicate that the version is known and the content on disk is the
291 * master (as speced with document content ownership).
293 * The version number of a document will increase after each change, including
294 * undo/redo. The number doesn't need to be consecutive.
296 public int version { get; set; default = -1; }
299 public class TextDocumentPositionParams : Object {
300 public TextDocumentIdentifier textDocument { get; set; }
301 public Position position { get; set; }
304 public class ReferenceParams : TextDocumentPositionParams {
305 public class ReferenceContext : Object {
306 public bool includeDeclaration { get; set; }
308 public ReferenceContext? context { get; set; }
311 public class Location : Object {
312 public string uri { get; set; }
313 public Range range { get; set; }
315 public Location.from_sourceref (Vala.SourceReference sref) {
316 this (sref.file.filename, new Range.from_sourceref (sref));
319 public Location (string filename, Range range) {
320 this.uri = File.new_for_commandline_arg (filename).get_uri ();
325 [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
326 public enum DocumentHighlightKind {
332 public class DocumentHighlight : Object {
333 public Range range { get; set; }
334 public DocumentHighlightKind kind { get; set; }
337 public class DocumentSymbolParams: Object {
338 public TextDocumentIdentifier textDocument { get; set; }
341 public class DocumentSymbol : Object, Json.Serializable {
342 private Vala.SourceReference? _source_reference;
343 public string name { get; set; }
344 public string detail { get; set; default = ""; }
345 public SymbolKind kind { get; set; }
346 public bool deprecated { get; set; }
348 public Range range { get; set; }
349 public Range selectionRange { get; set; }
350 public GLib.ListStore children { get; set; default = new GLib.ListStore(typeof(DocumentSymbol)); }
351 public string? parent_name;
353 private DocumentSymbol () {}
356 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
357 * @param sym the symbol
360 public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
361 this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
362 this._initial_range = new Range.from_sourceref (sym.source_reference);
363 if (sym is Vala.Subroutine) {
364 var sub = (Vala.Subroutine) sym;
365 var body_sref = sub.body != null ? sub.body.source_reference : null;
366 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
367 // body_sref != null ? body_sref.to_string () : null);
368 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
369 val = GLib.Value (typeof(Gee.ArrayList)); body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
370 this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
373 this.name = sym.name;
374 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
376 this.selectionRange = new Range.from_sourceref (sym.source_reference);
377 this.deprecated = sym.version.deprecated;
380 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
381 base.set_property (pspec.get_name (), value);
384 public new Value Json.Serializable.get_property (ParamSpec pspec) {
385 Value val = Value (pspec.value_type);
386 base.get_property (pspec.get_name (), ref val);
390 public unowned ParamSpec? find_property (string name) {
391 return this.get_class ().find_property (name);
394 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
395 // if (property_name != "children")
396 return default_serialize_property (property_name, value, pspec);
397 /*var node = new Json.Node (Json.NodeType.ARRAY);
398 node.init_array (new Json.Array ());
399 var array = node.get_array ();
400 foreach (var child in children)
401 array.add_element (Json.gobject_serialize (child));
406 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
408 GLib.debug("deserialise property %s" , property_name);
409 if (property_name != "children") {
410 return default_deserialize_property (property_name, out value, pspec, property_node);
412 value = GLib.Value (typeof(GLib.ListStore));
413 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
414 GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
417 GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
418 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
420 property_node.get_array ().foreach_element ((array, index, element) => {
422 var add= Json.gobject_deserialize ( typeof (DocumentSymbol), array.get_element(index)) as DocumentSymbol;
423 arguments.append( add);
428 value.set_object (arguments);
431 public string symbol_icon {
434 return this.kind.icon();
438 public string tooltip {
440 GLib.debug("%s : %s", this.name, this.detail);
441 //var detail = this.detail == "" ? (this.kind.to_string() + ": " + this.name) : this.detail;
442 return GLib.Markup.escape_text(this.detail + "\nline: " + this.range.start.line.to_string());
446 public string sort_key {
448 return this.kind.sort_key().to_string() + "=" + this.name;
452 public DocumentSymbol? containsLine(uint line, uint chr)
454 if (!this.range.contains(new Position(line, chr))) {
458 for(var i = 0; i < this.children.get_n_items();i++) {
459 var el = (DocumentSymbol)this.children.get_item(i);
460 var ret = el.containsLine(line,chr);
468 public bool equals(DocumentSymbol sym) {
469 return this.name == sym.name && this.kind == sym.kind && sym.range.equals(this.range);
475 public class SymbolInformation : Object {
476 public string name { get; set; }
477 public SymbolKind kind { get; set; }
478 public Location location { get; set; }
479 public string? containerName { get; set; }
481 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
482 this.name = dsym.name;
483 this.kind = dsym.kind;
484 // this.location = new Location (uri, dsym.range);
485 this.containerName = dsym.parent_name;
489 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
490 public enum SymbolKind {
518 public string icon () {
522 // case SymbolKind.Text: return "completion-snippet-symbolic";
523 case SymbolKind.Method: return "lang-method-symbolic";
524 case SymbolKind.Function: return "lang-function-symbolic";
525 case SymbolKind.Constructor: return "lang-method-symbolic";
526 case SymbolKind.Field: return "lang-struct-field-symbolic";
527 case SymbolKind.Variable: return "lang-variable-symbolic";
528 case SymbolKind.Class: return "lang-class-symbolic";
529 case SymbolKind.Interface: return "lang-class-symbolic";
530 case SymbolKind.Module: return "lang-namespace-symbolic";
531 case SymbolKind.Property:return "lang-struct-field-symbolic";
532 //case SymbolKind.Unit: return "lang-variable-symbolic";
533 //case SymbolKind.Value: return "lang-variable-symbolic";
534 case SymbolKind.Enum: return "lang-enum-symbolic";
535 //case SymbolKind.Keyword: return "completion-word-symbolic";
536 //case SymbolKind.Snippet: return "completion-snippet-symbolic";
538 //case SymbolKind.Color: return "lang-typedef-symbolic";
539 case SymbolKind.File:return "lang-typedef-symbolic";
540 //case SymbolKind.Reference: return "lang-typedef-symbolic";
541 //case SymbolKind.Folder:return "lang-typedef-symbolic";
542 case SymbolKind.EnumMember: return "lang-typedef-symbolic";
543 case SymbolKind.Constant:return "lang-typedef-symbolic";
544 case SymbolKind.Struct: return "lang-struct-symbolic";
545 case SymbolKind.Event:return "lang-typedef-symbolic";
546 case SymbolKind.Operator:return "lang-typedef-symbolic";
547 case SymbolKind.TypeParameter:return "lang-typedef-symbolic";
550 return "completion-snippet-symbolic";
554 public int sort_key() {
557 case Enum : return 1;
558 case Class: return 2;
560 case Constructor : return 1;
561 case Method : return 2;
562 case Field : return 3;
563 case Property : return 3;
575 public class CompletionList : Object, Json.Serializable {
576 public bool isIncomplete { get; set; }
577 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
579 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
580 base.set_property (pspec.get_name (), value);
583 public new Value Json.Serializable.get_property (ParamSpec pspec) {
584 Value val = Value(pspec.value_type);
585 base.get_property (pspec.get_name (), ref val);
589 public unowned ParamSpec? find_property (string name) {
590 return this.get_class ().find_property (name);
593 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
594 if (property_name != "items")
595 return default_serialize_property (property_name, value, pspec);
596 var node = new Json.Node (Json.NodeType.ARRAY);
597 node.init_array (new Json.Array ());
598 var array = node.get_array ();
599 foreach (var child in items)
600 array.add_element (Json.gobject_serialize (child));
604 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
605 error ("deserialization not supported");
609 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
610 public enum CompletionTriggerKind {
612 * Completion was triggered by typing an identifier (24x7 code
613 * complete), manual invocation (e.g Ctrl+Space) or via API.
618 * Completion was triggered by a trigger character specified by
619 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
621 TriggerCharacter = 2,
624 * Completion was re-triggered as the current completion list is incomplete.
626 TriggerForIncompleteCompletions = 3
629 public class CompletionContext : Object {
630 public CompletionTriggerKind triggerKind { get; set;}
631 public string? triggerCharacter { get; set; }
634 public class CompletionParams : TextDocumentPositionParams {
636 * The completion context. This is only available if the client specifies
637 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
639 public CompletionContext? context { get; set; }
642 public enum CompletionItemTag {
643 // Render a completion as obsolete, usually using a strike-out.
647 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
648 public enum InsertTextFormat {
650 * The primary text to be inserted is treated as a plain string.
655 * The primary text to be inserted is treated as a snippet.
657 * A snippet can define tab stops and placeholders with `$1`, `$2`
658 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
659 * the end of the snippet. Placeholders with equal identifiers are linked,
660 * that is typing in one will update others too.
665 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
666 public string label { get; set; }
667 public CompletionItemKind kind { get; set; }
668 public string detail { get; set; }
669 public MarkupContent? documentation { get; set; }
670 public bool deprecated { get; set; }
671 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
672 public string? insertText { get; set; }
673 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
676 private CompletionItem () {}
678 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
679 this.label = keyword;
680 this.kind = CompletionItemKind.Keyword;
681 this.insertText = insert_text;
682 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
683 this.insertTextFormat = InsertTextFormat.Snippet;
684 if (documentation != null)
685 this.documentation = new MarkupContent.from_plaintext (documentation);
686 this._hash = @"$label $kind".hash ();
690 * A completion suggestion from an existing Vala symbol.
692 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
693 * @param sym the symbol itself
694 * @param scope the scope to display this in
695 * @param kind the kind of completion to display
696 * @param documentation the documentation to display
697 * @param label_override if non-null, override the displayed symbol name with this
700 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
701 CompletionItemKind kind,
702 Vls.DocComment? documentation, string? label_override = null) {
703 this.label = label_override ?? sym.name;
705 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
706 this._hash = @"$label $kind".hash ();
708 if (documentation != null)
709 this.documentation = new MarkupContent.from_markdown (documentation.body);
711 var version = sym.get_attribute ("Version");
712 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
713 this.tags.add (CompletionItemTag.Deprecated);
714 this.deprecated = true;
719 * A completion suggestion from a data type and a synthetic symbol name.
721 * @param symbol_type the data type of the symbol
722 * @param symbol_name the name of the synthetic symbol
723 * @param scope the scope that this completion item is displayed in, or null
724 * @param kind the type of completion to display
725 * @param documentation the documentation for this symbol, or null
728 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
729 CompletionItemKind kind, Vls.DocComment? documentation) {
730 this.label = symbol_name;
732 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
733 this._hash = @"$label $kind".hash ();
735 if (documentation != null)
736 this.documentation = new MarkupContent.from_markdown (documentation.body);
740 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
741 string label, CompletionItemKind kind,
743 Vls.DocComment? documentation) {
746 this.insertText = insert_text;
747 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
748 this.insertTextFormat = InsertTextFormat.Snippet;
749 this._hash = @"$label $kind".hash ();
750 if (documentation != null)
751 this.documentation = new MarkupContent.from_markdown (documentation.body);
755 public uint hash () {
759 public bool equal_to (CompletionItem other) {
760 return other.label == this.label && other.kind == this.kind;
763 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
764 base.set_property (pspec.get_name (), value);
767 public new Value Json.Serializable.get_property (ParamSpec pspec) {
768 Value val = Value(pspec.value_type);
769 base.get_property (pspec.get_name (), ref val);
773 public unowned ParamSpec? find_property (string name) {
774 return this.get_class ().find_property (name);
777 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
778 if (property_name != "tags")
779 return default_serialize_property (property_name, value, pspec);
781 var node = new Json.Node (Json.NodeType.ARRAY);
782 node.init_array (new Json.Array ());
783 var array = node.get_array ();
784 foreach (var tag in this.tags) {
785 array.add_int_element (tag);
790 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
792 if (property_name != "tags") {
793 return default_deserialize_property (property_name, out value, pspec, property_node);
795 value = GLib.Value (typeof(Gee.ArrayList));
796 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
797 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
801 var arguments = new Gee.ArrayList<CompletionItemTag>();
803 property_node.get_array ().foreach_element ((array, index, element) => {
805 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
807 warning ("argument %u to command could not be deserialized: %s", index, e.message);
811 value.set_object (arguments);
816 public class MarkupContent : Object {
817 public string kind { get; set; }
818 public string value { get; set; }
820 private MarkupContent () {}
823 * Create a MarkupContent with plain text.
825 public MarkupContent.from_plaintext (string doc) {
826 this.kind = "plaintext";
831 * Create a MarkupContent with markdown text.
833 public MarkupContent.from_markdown (string doc) {
834 this.kind = "markdown";
839 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
840 public enum CompletionItemKind {
869 * Capabilities of the client/editor for `textDocument/documentSymbol`
871 public class DocumentSymbolCapabilities : Object {
872 public bool hierarchicalDocumentSymbolSupport { get; set; }
876 * Capabilities of the client/editor for `textDocument/rename`
878 public class RenameClientCapabilities : Object {
879 public bool prepareSupport { get; set; }
883 * Capabilities of the client/editor pertaining to language features.
885 public class TextDocumentClientCapabilities : Object {
886 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
887 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
891 * Capabilities of the client/editor.
893 public class ClientCapabilities : Object {
894 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
897 public class InitializeParams : Object {
898 public int processId { get; set; }
899 public string? rootPath { get; set; }
900 public string? rootUri { get; set; }
901 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
904 public class SignatureInformation : Object, Json.Serializable {
905 public string label { get; set; }
906 public MarkupContent documentation { get; set; }
908 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
910 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
911 base.set_property (pspec.get_name (), value);
914 public new Value Json.Serializable.get_property (ParamSpec pspec) {
915 Value val = Value(pspec.value_type);
916 base.get_property (pspec.get_name (), ref val);
920 public unowned ParamSpec? find_property (string name) {
921 return this.get_class ().find_property (name);
924 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
925 if (property_name != "parameters")
926 return default_serialize_property (property_name, value, pspec);
927 var node = new Json.Node (Json.NodeType.ARRAY);
928 node.init_array (new Json.Array ());
929 var array = node.get_array ();
930 foreach (var child in parameters)
931 array.add_element (Json.gobject_serialize (child));
935 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
936 error ("deserialization not supported");
940 public class SignatureHelp : Object, Json.Serializable {
941 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
942 public int activeSignature { get; set; }
943 public int activeParameter { get; set; }
945 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
946 if (property_name != "signatures")
947 return default_serialize_property (property_name, value, pspec);
949 var node = new Json.Node (Json.NodeType.ARRAY);
950 node.init_array (new Json.Array ());
951 var array = node.get_array ();
952 foreach (var child in signatures)
953 array.add_element (Json.gobject_serialize (child));
957 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
958 error ("deserialization not supported");
962 public class ParameterInformation : Object {
963 public string label { get; set; }
964 public MarkupContent documentation { get; set; }
967 public class MarkedString : Object {
968 public MarkedString(string language, string value)
970 this.language = language;
972 GLib.debug("new marked string %s : %s", language, value);
974 public string language { get; set; }
975 public string value { get; set; }
978 public class Hover : Object, Json.Serializable {
979 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
980 public Range range { get; set; }
982 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
983 base.set_property (pspec.get_name (), value);
986 public new Value Json.Serializable.get_property (ParamSpec pspec) {
987 Value val = Value(pspec.value_type);
988 base.get_property (pspec.get_name (), ref val);
992 public unowned ParamSpec? find_property (string name) {
993 return this.get_class ().find_property (name);
996 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
997 if (property_name != "contents")
998 return default_serialize_property (property_name, value, pspec);
999 var node = new Json.Node (Json.NodeType.ARRAY);
1000 node.init_array (new Json.Array ());
1001 var array = node.get_array ();
1002 foreach (var child in contents) {
1003 if (child.language != null)
1004 array.add_element (Json.gobject_serialize (child));
1006 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
1011 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
1013 if (property_name == "contents") {
1014 value = GLib.Value (typeof(Gee.ArrayList));
1015 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1016 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1019 var contents = new Gee.ArrayList<MarkedString>();
1021 property_node.get_array ().foreach_element ((array, index, element) => {
1023 var add = new MarkedString(
1024 array.get_object_element(index).get_string_member("language"),
1025 array.get_object_element(index).get_string_member("value")
1028 contents.add ( add );
1030 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1033 value.set_object (contents);
1037 return default_deserialize_property (property_name, out value, pspec, property_node);
1042 * A textual edit applicable to a text document.
1044 public class TextEdit : Object {
1046 * The range of the text document to be manipulated. To insert
1047 * text into a document create a range where ``start === end``.
1049 public Range range { get; set; }
1052 * The string to be inserted. For delete operations use an
1055 public string newText { get; set; }
1057 public TextEdit (Range range, string new_text = "") {
1059 this.newText = new_text;
1064 * Describes textual changes on a single text document. The text document is
1065 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
1066 * check the text document version before an edit is applied. A
1067 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
1068 * applied move the document to version ``Si+1``. So the creator of a
1069 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
1070 * of ordering. However the edits must be non overlapping.
1072 public class TextDocumentEdit : Object, Json.Serializable {
1074 * The text document to change.
1076 public VersionedTextDocumentIdentifier textDocument { get; set; }
1079 * The edits to be applied.
1081 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
1083 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
1084 this.textDocument = text_document;
1087 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1088 if (property_name != "edits")
1089 return default_serialize_property (property_name, value, pspec);
1091 var node = new Json.Node (Json.NodeType.ARRAY);
1092 node.init_array (new Json.Array ());
1093 var array = node.get_array ();
1094 foreach (var text_edit in edits) {
1095 array.add_element (Json.gobject_serialize (text_edit));
1100 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1101 error ("deserialization not supported");
1105 public abstract class CommandLike : Object, Json.Serializable {
1107 * The identifier of the actual command handler.
1109 public string command { get; set; }
1112 * Arguments that the command handler should be invoked with.
1114 public Array<Variant>? arguments { get; set; }
1116 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1117 if (property_name != "arguments" || arguments == null)
1118 return default_serialize_property (property_name, value, pspec);
1120 var array = new Json.Array ();
1121 for (int i = 0; i < arguments.length; i++)
1122 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1124 var node = new Json.Node (Json.NodeType.ARRAY);
1125 node.set_array (array);
1129 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1131 if (property_name == "arguments") {
1132 value = GLib.Value (typeof(Array));
1133 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1134 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1138 var arguments = new Array<Variant> ();
1140 property_node.get_array ().foreach_element ((array, index, element) => {
1142 arguments.append_val (Json.gvariant_deserialize (element, null));
1144 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1148 value.set_boxed (arguments);
1150 } else if (property_name == "command") {
1151 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1152 if (property_node.get_value_type () != typeof (string)) {
1154 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1158 value = property_node.get_string ();
1161 return default_deserialize_property (property_name, out value, pspec, property_node);
1166 public class ExecuteCommandParams : CommandLike {
1170 * Represents a reference to a command. Provides a title which will be used
1171 * to represent a command in the UI. Commands are identified by a string
1172 * identifier. The recommended way to handle commands is to implement their
1173 * execution on the server side if the client and server provides the
1174 * corresponding capabilities. Alternatively the tool extension code could
1175 * handle the command. The protocol currently doesn’t specify a set of
1176 * well-known commands.
1178 public class Command : CommandLike {
1180 * The title of the command, like `save`.
1182 public string title { get; set; }
1186 * A code lens represents a command that should be shown along with
1187 * source text, like the number of references, a way to run tests, etc.
1189 * A code lens is _unresolved_ when no command is associated to it. For
1190 * performance reasons the creation of a code lens and resolving should be done
1193 public class CodeLens : Object {
1195 * The range in which this code lens is valid. Should only span a single
1198 public Range range { get; set; }
1201 * The command this code lens represents.
1203 public Command? command { get; set; }
1206 public class DocumentRangeFormattingParams : Object {
1207 public TextDocumentIdentifier textDocument { get; set; }
1208 public Range? range { get; set; }
1209 public FormattingOptions options { get; set; }
1212 public class FormattingOptions : Object {
1213 public uint tabSize { get; set; }
1214 public bool insertSpaces { get; set; }
1215 public bool trimTrailingWhitespace { get; set; }
1216 public bool insertFinalNewline { get; set; }
1217 public bool trimFinalNewlines { get; set; }
1220 public class CodeActionParams : Object {
1221 public TextDocumentIdentifier textDocument { get; set; }
1222 public Range range { get; set; }
1223 public CodeActionContext context { get; set; }
1227 public class CodeActionContext : Object, Json.Serializable {
1228 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1229 public string[]? only { get; set; }
1231 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1232 if (property_name != "diagnostics")
1233 return default_deserialize_property (property_name, out value, pspec, property_node);
1234 var diags = new Gee.ArrayList<Diagnostic> ();
1235 property_node.get_array ().foreach_element ((array, index, element) => {
1237 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1239 warning ("argument %u could not be deserialized: %s", index, e.message);
1249 public class Diagnostics : Object, Json.Serializable
1251 public Diagnostics()
1253 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1258 public string uri { get; set; }
1260 public int version { get; set; default = 0; }
1261 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1263 public string filename {
1265 return File.new_for_uri (this.uri).get_path();
1270 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1271 if (property_name == "diagnostics") {
1272 val = GLib.Value (typeof(Gee.ArrayList));
1273 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1276 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1277 val.set_object(diags);
1278 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1284 property_node.get_array ().foreach_element ((array, index, element) => {
1286 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1288 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1291 val.set_object(diags);
1296 return default_deserialize_property (property_name, out val, pspec, property_node);
1304 public class CodeAction : Object, Json.Serializable {
1305 public string title { get; set; }
1306 public string? kind { get; set; }
1307 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1308 public bool isPreferred { get; set; }
1309 public WorkspaceEdit? edit { get; set; }
1310 public Command? command { get; set; }
1311 public Object? data { get; set; }
1313 protected void add_diagnostic (Diagnostic diag) {
1314 if (diagnostics == null)
1315 diagnostics = new Gee.ArrayList<Diagnostic> ();
1316 diagnostics.add (diag);
1319 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1320 if (property_name != "diagnostics")
1321 return default_serialize_property (property_name, value, pspec);
1323 var array = new Json.Array ();
1324 if (diagnostics != null)
1325 foreach (var text_edit in diagnostics)
1326 array.add_element (Json.gobject_serialize (text_edit));
1327 return new Json.Node.alloc ().init_array (array);
1331 public class WorkspaceEdit : Object, Json.Serializable {
1332 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1334 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1335 if (property_name != "documentChanges")
1336 return default_serialize_property (property_name, value, pspec);
1338 var node = new Json.Node (Json.NodeType.ARRAY);
1339 node.init_array (new Json.Array ());
1340 if (documentChanges != null) {
1341 var array = node.get_array ();
1342 foreach (var text_edit in documentChanges) {
1343 array.add_element (Json.gobject_serialize (text_edit));
1351 public enum SymbolTags {
1356 public class CallHierarchyItem : Object, Json.Serializable {
1357 public string name { get; set; }
1358 public SymbolKind kind { get; set; }
1359 public SymbolTags tags { get; set; }
1360 public string? detail { get; set; }
1361 public string uri { get; set; }
1362 public Range range { get; set; }
1363 public Range selectionRange { get; set; }
1365 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1366 if (property_name != "tags")
1367 return default_serialize_property (property_name, value, pspec);
1368 var array = new Json.Array ();
1369 if (SymbolTags.DEPRECATED in tags)
1370 array.add_int_element (SymbolTags.DEPRECATED);
1371 return new Json.Node.alloc ().init_array (array);
1374 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1375 this.name = symbol.get_full_name ();
1376 if (symbol is Vala.Method) {
1377 if (symbol.parent_symbol is Vala.Namespace)
1378 this.kind = SymbolKind.Function;
1380 this.kind = SymbolKind.Method;
1381 } else if (symbol is Vala.Signal) {
1382 this.kind = SymbolKind.Event;
1383 } else if (symbol is Vala.Constructor) {
1384 this.kind = SymbolKind.Constructor;
1386 this.kind = SymbolKind.Method;
1388 var version = symbol.get_attribute ("Version");
1389 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1390 this.tags |= SymbolTags.DEPRECATED;
1392 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1393 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1394 this.range = new Range.from_sourceref (symbol.source_reference);
1395 if (symbol.comment != null)
1396 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1397 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1398 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1399 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1404 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1406 * The method that calls the query method.
1408 public CallHierarchyItem from { get; set; }
1411 * The ranges at which the query method is called by `from`.
1413 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1415 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1416 if (property_name == "from")
1417 return default_serialize_property (property_name, value, pspec);
1418 var array = new Json.Array ();
1419 foreach (var range in fromRanges)
1420 array.add_element (Json.gobject_serialize (range));
1421 return new Json.Node.alloc ().init_array (array);
1425 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1427 * The method that the query method calls.
1429 public CallHierarchyItem to { get; set; }
1432 * The ranges at which the method is called by the query method.
1434 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1436 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1437 if (property_name == "to")
1438 return default_serialize_property (property_name, value, pspec);
1439 var array = new Json.Array ();
1440 foreach (var range in fromRanges)
1441 array.add_element (Json.gobject_serialize (range));
1442 return new Json.Node.alloc ().init_array (array);
1446 public class InlayHintParams : Json.Serializable, Object {
1447 public TextDocumentIdentifier textDocument { get; set; }
1448 public Range range { get; set; }
1451 public enum InlayHintKind {
1457 public class InlayHint : Object {
1458 public Position position { get; set; }
1459 public string label { get; set; }
1460 public InlayHintKind kind { get; set; }
1461 public string? tooltip { get; set; }
1462 public bool paddingLeft { get; set; }
1463 public bool paddingRight { get; set; }
1466 public class TypeHierarchyItem : Object, Json.Serializable {
1468 * The name of this item
1470 public string name { get; set; }
1473 * The kind of this item
1475 public SymbolKind kind { get; set; }
1478 * Tags for this item
1480 public SymbolTags tags { get; set; }
1483 * More detail for this item, e.g. the signature of a function.
1485 public string? detail { get; set; }
1488 * The resource identifier of this item.
1490 public string uri { get; set; }
1493 * The range enclosing this symbol not including leading/trailing
1494 * whitespace, but everything else, e.g. comments and code.
1496 public Range range { get; set; }
1499 * The range that should be selected and revealed when this symbol
1500 * is being picked, e.g. the name of a function. Must be contained
1501 * by {@link TypeHierarchyItem.range}
1503 public Range selectionRange { get; set; }
1505 private TypeHierarchyItem () {}
1507 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1508 this.name = symbol.get_full_name ();
1509 if (symbol is Vala.Class)
1510 this.kind = SymbolKind.Class;
1511 else if (symbol is Vala.Delegate)
1512 this.kind = SymbolKind.Interface;
1513 else if (symbol is Vala.Enum)
1514 this.kind = SymbolKind.Enum;
1515 else if (symbol is Vala.ErrorCode)
1516 this.kind = SymbolKind.EnumMember;
1517 else if (symbol is Vala.ErrorDomain)
1518 this.kind = SymbolKind.Enum;
1519 else if (symbol is Vala.Interface)
1520 this.kind = SymbolKind.Interface;
1521 else if (symbol is Vala.Struct)
1522 this.kind = SymbolKind.Struct;
1523 else if (symbol is Vala.TypeParameter)
1524 this.kind = SymbolKind.TypeParameter;
1526 this.kind = SymbolKind.Module;
1527 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1530 var version = symbol.get_attribute ("Version");
1531 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1532 this.tags |= SymbolTags.DEPRECATED;
1534 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1535 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1536 this.range = new Range.from_sourceref (symbol.source_reference);
1537 this.selectionRange = this.range;
1539 // widen range to include all members
1540 if (symbol is Vala.ObjectTypeSymbol) {
1541 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1542 if (member.source_reference != null)
1543 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1545 } else if (symbol is Vala.Enum) {
1546 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1547 if (member.source_reference != null)
1548 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1550 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1551 if (method.source_reference != null)
1552 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1554 } else if (symbol is Vala.ErrorDomain) {
1555 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1556 if (member.source_reference != null)
1557 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1559 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1560 if (method.source_reference != null)
1561 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1563 } else if (symbol is Vala.Struct) {
1564 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1565 if (field.source_reference != null)
1566 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1568 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1569 if (method.source_reference != null)
1570 this.range = this.range.union (new Range.from_sourceref (method.source_reference));