3 * Copyright 2017-2019 Ben Iofel <ben@iofel.me>
4 * Copyright 2017-2020 Princeton Ferro <princetonferro@gmail.com>
5 * Copyright 2020 Sergii Fesenko <s.fesenko@outlook.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * Defines how the host (editor) should sync document changes to the language server.
25 [CCode (default_value = "LSP_TEXT_DOCUMENT_SYNC_KIND_Unset")]
26 public enum TextDocumentSyncKind {
29 * Documents should not be synced at all.
33 * Documents are synced by always sending the full content of the document.
37 * Documents are synced by sending the full content on open. After that only incremental
38 * updates to the document are sent.
43 public enum DiagnosticSeverity {
54 * Reports an information.
64 public class Position : Object, Gee.Comparable<Position> {
66 * Line position in a document (zero-based).
68 public uint line { get; set; default = -1; }
71 * Character offset on a line in a document (zero-based). Assuming that the line is
72 * represented as a string, the `character` value represents the gap between the
73 * `character` and `character + 1`.
75 * If the character value is greater than the line length it defaults back to the
78 public uint character { get; set; default = -1; }
80 public int compare_to (Position other) {
81 return line > other.line ? 1 :
83 (character > other.character ? 1 :
84 (character == other.character ? 0 : -1)) : -1);
86 public bool equals(Position o) {
87 return o.line == this.line && o.character == this.character;
90 public string to_string () {
91 return @"$line:$character";
94 public Position.from_libvala (Vala.SourceLocation sloc) {
96 character = sloc.column;
99 public Position dup () {
100 return this.translate ();
103 public Position translate (int dl = 0, int dc = 0) {
104 return new Position () {
105 line = this.line + dl,
106 character = this.character + dc
111 public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
113 public Range.simple(uint line, uint pos) {
114 var p = new Position () {
123 * The range's start position.
125 public Position start { get; set; }
128 * The range's end position.
130 public Position end { get; set; }
132 private string? filename;
134 public string to_string () { return (filename != null ? @"$filename:" : "") + @"$start -> $end"; }
136 public Range.from_pos (Position pos) {
138 this.end = pos.dup ();
141 public Range.from_sourceref (Vala.SourceReference sref) {
142 this.start = new Position.from_libvala (sref.begin);
143 this.end = new Position.from_libvala (sref.end);
144 this.start.character -= 1;
145 this.filename = sref.file.filename;
148 public uint hash () {
149 return this.to_string ().hash ();
152 public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
153 public bool equals (Range o) {
154 return this.filename == o.filename && this.start.equals(o.start) && this.end.equals(o.end);
157 public int compare_to (Range other) {
158 return start.compare_to (other.start);
162 * Return a new range that includes `this` and `other`.
164 public Range union (Range other) {
165 var range = new Range () {
166 start = start.compare_to (other.start) < 0 ? start : other.start,
167 end = end.compare_to (other.end) < 0 ? other.end : end,
169 if (filename == other.filename)
170 range.filename = filename;
174 public bool contains (Position pos) {
175 return start.compare_to (pos) <= 0 && pos.compare_to (end) <= 0;
180 public class Diagnostic : Object {
182 public Diagnostic.simple ( int line, int character, string message)
184 this.message = message;
185 this.severity = DiagnosticSeverity.Error;
186 this.range = new Range.simple(line, character );
192 * The range at which the message applies.
194 public Range range { get; set; }
197 * The diagnostic's severity. Can be omitted. If omitted it is up to the
198 * client to interpret diagnostics as error, warning, info or hint.
200 public DiagnosticSeverity severity { get; set; }
203 * The diagnostic's code. Can be omitted.
205 public string? code { get; set; }
208 * A human-readable string describing the source of this
209 * diagnostic, e.g. 'typescript' or 'super lint'.
211 public string? source { get; set; }
214 * The diagnostic's message.
216 public string message { get; set; }
219 public string category {
221 switch(this.severity) {
223 case DiagnosticSeverity.Error :
225 case DiagnosticSeverity.Warning :
226 return this.message.contains("deprecated") ? "DEPR" : "WARN";
234 public bool equals(Lsp.Diagnostic o) {
235 var ret = this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
236 //GLib.debug("compare %s (%s == %s)", ret ? "YES" : "NO", this.to_string(), o.to_string());
241 public string to_string()
243 return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
249 * An event describing a change to a text document. If range and rangeLength are omitted
250 * the new text is considered to be the full content of the document.
252 public class TextDocumentContentChangeEvent : Object {
253 public Range? range { get; set; }
254 public int rangeLength { get; set; }
255 public string text { get; set; }
258 public enum MessageType {
268 * An information message.
277 public class TextDocumentIdentifier : Object {
278 public string uri { get; set; }
281 public class VersionedTextDocumentIdentifier : TextDocumentIdentifier {
283 * The version number of this document. If a versioned text document identifier
284 * is sent from the server to the client and the file is not open in the editor
285 * (the server has not received an open notification before) the server can send
286 * `null` to indicate that the version is known and the content on disk is the
287 * master (as speced with document content ownership).
289 * The version number of a document will increase after each change, including
290 * undo/redo. The number doesn't need to be consecutive.
292 public int version { get; set; default = -1; }
295 public class TextDocumentPositionParams : Object {
296 public TextDocumentIdentifier textDocument { get; set; }
297 public Position position { get; set; }
300 public class ReferenceParams : TextDocumentPositionParams {
301 public class ReferenceContext : Object {
302 public bool includeDeclaration { get; set; }
304 public ReferenceContext? context { get; set; }
307 public class Location : Object {
308 public string uri { get; set; }
309 public Range range { get; set; }
311 public Location.from_sourceref (Vala.SourceReference sref) {
312 this (sref.file.filename, new Range.from_sourceref (sref));
315 public Location (string filename, Range range) {
316 this.uri = File.new_for_commandline_arg (filename).get_uri ();
321 [CCode (default_value = "LSP_DOCUMENT_HIGHLIGHT_KIND_Text")]
322 public enum DocumentHighlightKind {
328 public class DocumentHighlight : Object {
329 public Range range { get; set; }
330 public DocumentHighlightKind kind { get; set; }
333 public class DocumentSymbolParams: Object {
334 public TextDocumentIdentifier textDocument { get; set; }
337 public class DocumentSymbol : Object, Json.Serializable {
338 private Vala.SourceReference? _source_reference;
339 public string name { get; set; }
340 public string detail { get; set; default = ""; }
341 public SymbolKind kind { get; set; }
342 public bool deprecated { get; set; }
344 public Range range { get; set; }
345 public Range selectionRange { get; set; }
346 public GLib.ListStore children { get; set; default = new GLib.ListStore(typeof(DocumentSymbol)); }
347 public string? parent_name;
349 private DocumentSymbol () {}
352 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
353 * @param sym the symbol
356 public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
357 this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
358 this._initial_range = new Range.from_sourceref (sym.source_reference);
359 if (sym is Vala.Subroutine) {
360 var sub = (Vala.Subroutine) sym;
361 var body_sref = sub.body != null ? sub.body.source_reference : null;
362 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
363 // body_sref != null ? body_sref.to_string () : null);
364 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
365 val = GLib.Value (typeof(Gee.ArrayList)); body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
366 this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
369 this.name = sym.name;
370 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
372 this.selectionRange = new Range.from_sourceref (sym.source_reference);
373 this.deprecated = sym.version.deprecated;
376 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
377 base.set_property (pspec.get_name (), value);
380 public new Value Json.Serializable.get_property (ParamSpec pspec) {
381 Value val = Value (pspec.value_type);
382 base.get_property (pspec.get_name (), ref val);
386 public unowned ParamSpec? find_property (string name) {
387 return this.get_class ().find_property (name);
390 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
391 // if (property_name != "children")
392 return default_serialize_property (property_name, value, pspec);
393 /*var node = new Json.Node (Json.NodeType.ARRAY);
394 node.init_array (new Json.Array ());
395 var array = node.get_array ();
396 foreach (var child in children)
397 array.add_element (Json.gobject_serialize (child));
402 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
404 GLib.debug("deserialise property %s" , property_name);
405 if (property_name != "children") {
406 return default_deserialize_property (property_name, out value, pspec, property_node);
408 value = GLib.Value (typeof(GLib.ListStore));
409 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
410 GLib.debug ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
413 GLib.debug("got child length of %d", (int) property_node.get_array ().get_length());
414 var arguments = new GLib.ListStore(typeof(DocumentSymbol));
416 property_node.get_array ().foreach_element ((array, index, element) => {
418 var add= Json.gobject_deserialize ( typeof (DocumentSymbol), array.get_element(index)) as DocumentSymbol;
419 arguments.append( add);
424 value.set_object (arguments);
427 public string symbol_icon {
430 return this.kind.icon();
433 public string[] symbol_classes {
437 ret += 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());
453 public class SymbolInformation : Object {
454 public string name { get; set; }
455 public SymbolKind kind { get; set; }
456 public Location location { get; set; }
457 public string? containerName { get; set; }
459 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
460 this.name = dsym.name;
461 this.kind = dsym.kind;
462 // this.location = new Location (uri, dsym.range);
463 this.containerName = dsym.parent_name;
467 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
468 public enum SymbolKind {
496 public string icon () {
500 // case SymbolKind.Text: return "completion-snippet-symbolic";
501 case SymbolKind.Method: return "lang-method-symbolic";
502 case SymbolKind.Function: return "lang-function-symbolic";
503 case SymbolKind.Constructor: return "lang-method-symbolic";
504 case SymbolKind.Field: return "lang-struct-field-symbolic";
505 case SymbolKind.Variable: return "lang-variable-symbolic";
506 case SymbolKind.Class: return "lang-class-symbolic";
507 case SymbolKind.Interface: return "lang-class-symbolic";
508 case SymbolKind.Module: return "lang-namespace-symbolic";
509 case SymbolKind.Property:return "lang-struct-field-symbolic";
510 //case SymbolKind.Unit: return "lang-variable-symbolic";
511 //case SymbolKind.Value: return "lang-variable-symbolic";
512 case SymbolKind.Enum: return "lang-enum-symbolic";
513 //case SymbolKind.Keyword: return "completion-word-symbolic";
514 //case SymbolKind.Snippet: return "completion-snippet-symbolic";
516 //case SymbolKind.Color: return "lang-typedef-symbolic";
517 case SymbolKind.File:return "lang-typedef-symbolic";
518 //case SymbolKind.Reference: return "lang-typedef-symbolic";
519 //case SymbolKind.Folder:return "lang-typedef-symbolic";
520 case SymbolKind.EnumMember: return "lang-typedef-symbolic";
521 case SymbolKind.Constant:return "lang-typedef-symbolic";
522 case SymbolKind.Struct: return "lang-struct-symbolic";
523 case SymbolKind.Event:return "lang-typedef-symbolic";
524 case SymbolKind.Operator:return "lang-typedef-symbolic";
525 case SymbolKind.TypeParameter:return "lang-typedef-symbolic";
528 return "completion-snippet-symbolic";
535 public class CompletionList : Object, Json.Serializable {
536 public bool isIncomplete { get; set; }
537 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
539 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
540 base.set_property (pspec.get_name (), value);
543 public new Value Json.Serializable.get_property (ParamSpec pspec) {
544 Value val = Value(pspec.value_type);
545 base.get_property (pspec.get_name (), ref val);
549 public unowned ParamSpec? find_property (string name) {
550 return this.get_class ().find_property (name);
553 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
554 if (property_name != "items")
555 return default_serialize_property (property_name, value, pspec);
556 var node = new Json.Node (Json.NodeType.ARRAY);
557 node.init_array (new Json.Array ());
558 var array = node.get_array ();
559 foreach (var child in items)
560 array.add_element (Json.gobject_serialize (child));
564 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
565 error ("deserialization not supported");
569 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
570 public enum CompletionTriggerKind {
572 * Completion was triggered by typing an identifier (24x7 code
573 * complete), manual invocation (e.g Ctrl+Space) or via API.
578 * Completion was triggered by a trigger character specified by
579 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
581 TriggerCharacter = 2,
584 * Completion was re-triggered as the current completion list is incomplete.
586 TriggerForIncompleteCompletions = 3
589 public class CompletionContext : Object {
590 public CompletionTriggerKind triggerKind { get; set;}
591 public string? triggerCharacter { get; set; }
594 public class CompletionParams : TextDocumentPositionParams {
596 * The completion context. This is only available if the client specifies
597 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
599 public CompletionContext? context { get; set; }
602 public enum CompletionItemTag {
603 // Render a completion as obsolete, usually using a strike-out.
607 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
608 public enum InsertTextFormat {
610 * The primary text to be inserted is treated as a plain string.
615 * The primary text to be inserted is treated as a snippet.
617 * A snippet can define tab stops and placeholders with `$1`, `$2`
618 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
619 * the end of the snippet. Placeholders with equal identifiers are linked,
620 * that is typing in one will update others too.
625 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
626 public string label { get; set; }
627 public CompletionItemKind kind { get; set; }
628 public string detail { get; set; }
629 public MarkupContent? documentation { get; set; }
630 public bool deprecated { get; set; }
631 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
632 public string? insertText { get; set; }
633 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
636 private CompletionItem () {}
638 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
639 this.label = keyword;
640 this.kind = CompletionItemKind.Keyword;
641 this.insertText = insert_text;
642 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
643 this.insertTextFormat = InsertTextFormat.Snippet;
644 if (documentation != null)
645 this.documentation = new MarkupContent.from_plaintext (documentation);
646 this._hash = @"$label $kind".hash ();
650 * A completion suggestion from an existing Vala symbol.
652 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
653 * @param sym the symbol itself
654 * @param scope the scope to display this in
655 * @param kind the kind of completion to display
656 * @param documentation the documentation to display
657 * @param label_override if non-null, override the displayed symbol name with this
660 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
661 CompletionItemKind kind,
662 Vls.DocComment? documentation, string? label_override = null) {
663 this.label = label_override ?? sym.name;
665 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
666 this._hash = @"$label $kind".hash ();
668 if (documentation != null)
669 this.documentation = new MarkupContent.from_markdown (documentation.body);
671 var version = sym.get_attribute ("Version");
672 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
673 this.tags.add (CompletionItemTag.Deprecated);
674 this.deprecated = true;
679 * A completion suggestion from a data type and a synthetic symbol name.
681 * @param symbol_type the data type of the symbol
682 * @param symbol_name the name of the synthetic symbol
683 * @param scope the scope that this completion item is displayed in, or null
684 * @param kind the type of completion to display
685 * @param documentation the documentation for this symbol, or null
688 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
689 CompletionItemKind kind, Vls.DocComment? documentation) {
690 this.label = symbol_name;
692 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
693 this._hash = @"$label $kind".hash ();
695 if (documentation != null)
696 this.documentation = new MarkupContent.from_markdown (documentation.body);
700 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
701 string label, CompletionItemKind kind,
703 Vls.DocComment? documentation) {
706 this.insertText = insert_text;
707 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
708 this.insertTextFormat = InsertTextFormat.Snippet;
709 this._hash = @"$label $kind".hash ();
710 if (documentation != null)
711 this.documentation = new MarkupContent.from_markdown (documentation.body);
715 public uint hash () {
719 public bool equal_to (CompletionItem other) {
720 return other.label == this.label && other.kind == this.kind;
723 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
724 base.set_property (pspec.get_name (), value);
727 public new Value Json.Serializable.get_property (ParamSpec pspec) {
728 Value val = Value(pspec.value_type);
729 base.get_property (pspec.get_name (), ref val);
733 public unowned ParamSpec? find_property (string name) {
734 return this.get_class ().find_property (name);
737 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
738 if (property_name != "tags")
739 return default_serialize_property (property_name, value, pspec);
741 var node = new Json.Node (Json.NodeType.ARRAY);
742 node.init_array (new Json.Array ());
743 var array = node.get_array ();
744 foreach (var tag in this.tags) {
745 array.add_int_element (tag);
750 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
752 if (property_name != "tags") {
753 return default_deserialize_property (property_name, out value, pspec, property_node);
755 value = GLib.Value (typeof(Gee.ArrayList));
756 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
757 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
761 var arguments = new Gee.ArrayList<CompletionItemTag>();
763 property_node.get_array ().foreach_element ((array, index, element) => {
765 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
767 warning ("argument %u to command could not be deserialized: %s", index, e.message);
771 value.set_object (arguments);
776 public class MarkupContent : Object {
777 public string kind { get; set; }
778 public string value { get; set; }
780 private MarkupContent () {}
783 * Create a MarkupContent with plain text.
785 public MarkupContent.from_plaintext (string doc) {
786 this.kind = "plaintext";
791 * Create a MarkupContent with markdown text.
793 public MarkupContent.from_markdown (string doc) {
794 this.kind = "markdown";
799 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
800 public enum CompletionItemKind {
829 * Capabilities of the client/editor for `textDocument/documentSymbol`
831 public class DocumentSymbolCapabilities : Object {
832 public bool hierarchicalDocumentSymbolSupport { get; set; }
836 * Capabilities of the client/editor for `textDocument/rename`
838 public class RenameClientCapabilities : Object {
839 public bool prepareSupport { get; set; }
843 * Capabilities of the client/editor pertaining to language features.
845 public class TextDocumentClientCapabilities : Object {
846 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
847 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
851 * Capabilities of the client/editor.
853 public class ClientCapabilities : Object {
854 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
857 public class InitializeParams : Object {
858 public int processId { get; set; }
859 public string? rootPath { get; set; }
860 public string? rootUri { get; set; }
861 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
864 public class SignatureInformation : Object, Json.Serializable {
865 public string label { get; set; }
866 public MarkupContent documentation { get; set; }
868 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
870 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
871 base.set_property (pspec.get_name (), value);
874 public new Value Json.Serializable.get_property (ParamSpec pspec) {
875 Value val = Value(pspec.value_type);
876 base.get_property (pspec.get_name (), ref val);
880 public unowned ParamSpec? find_property (string name) {
881 return this.get_class ().find_property (name);
884 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
885 if (property_name != "parameters")
886 return default_serialize_property (property_name, value, pspec);
887 var node = new Json.Node (Json.NodeType.ARRAY);
888 node.init_array (new Json.Array ());
889 var array = node.get_array ();
890 foreach (var child in parameters)
891 array.add_element (Json.gobject_serialize (child));
895 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
896 error ("deserialization not supported");
900 public class SignatureHelp : Object, Json.Serializable {
901 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
902 public int activeSignature { get; set; }
903 public int activeParameter { get; set; }
905 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
906 if (property_name != "signatures")
907 return default_serialize_property (property_name, value, pspec);
909 var node = new Json.Node (Json.NodeType.ARRAY);
910 node.init_array (new Json.Array ());
911 var array = node.get_array ();
912 foreach (var child in signatures)
913 array.add_element (Json.gobject_serialize (child));
917 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
918 error ("deserialization not supported");
922 public class ParameterInformation : Object {
923 public string label { get; set; }
924 public MarkupContent documentation { get; set; }
927 public class MarkedString : Object {
928 public MarkedString(string language, string value)
930 this.language = language;
932 GLib.debug("new marked string %s : %s", language, value);
934 public string language { get; set; }
935 public string value { get; set; }
938 public class Hover : Object, Json.Serializable {
939 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
940 public Range range { get; set; }
942 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
943 base.set_property (pspec.get_name (), value);
946 public new Value Json.Serializable.get_property (ParamSpec pspec) {
947 Value val = Value(pspec.value_type);
948 base.get_property (pspec.get_name (), ref val);
952 public unowned ParamSpec? find_property (string name) {
953 return this.get_class ().find_property (name);
956 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
957 if (property_name != "contents")
958 return default_serialize_property (property_name, value, pspec);
959 var node = new Json.Node (Json.NodeType.ARRAY);
960 node.init_array (new Json.Array ());
961 var array = node.get_array ();
962 foreach (var child in contents) {
963 if (child.language != null)
964 array.add_element (Json.gobject_serialize (child));
966 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
971 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
973 if (property_name == "contents") {
974 value = GLib.Value (typeof(Gee.ArrayList));
975 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
976 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
979 var contents = new Gee.ArrayList<MarkedString>();
981 property_node.get_array ().foreach_element ((array, index, element) => {
983 var add = new MarkedString(
984 array.get_object_element(index).get_string_member("language"),
985 array.get_object_element(index).get_string_member("value")
988 contents.add ( add );
990 warning ("argument %u to command could not be deserialized: %s", index, e.message);
993 value.set_object (contents);
997 return default_deserialize_property (property_name, out value, pspec, property_node);
1002 * A textual edit applicable to a text document.
1004 public class TextEdit : Object {
1006 * The range of the text document to be manipulated. To insert
1007 * text into a document create a range where ``start === end``.
1009 public Range range { get; set; }
1012 * The string to be inserted. For delete operations use an
1015 public string newText { get; set; }
1017 public TextEdit (Range range, string new_text = "") {
1019 this.newText = new_text;
1024 * Describes textual changes on a single text document. The text document is
1025 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
1026 * check the text document version before an edit is applied. A
1027 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
1028 * applied move the document to version ``Si+1``. So the creator of a
1029 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
1030 * of ordering. However the edits must be non overlapping.
1032 public class TextDocumentEdit : Object, Json.Serializable {
1034 * The text document to change.
1036 public VersionedTextDocumentIdentifier textDocument { get; set; }
1039 * The edits to be applied.
1041 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
1043 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
1044 this.textDocument = text_document;
1047 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1048 if (property_name != "edits")
1049 return default_serialize_property (property_name, value, pspec);
1051 var node = new Json.Node (Json.NodeType.ARRAY);
1052 node.init_array (new Json.Array ());
1053 var array = node.get_array ();
1054 foreach (var text_edit in edits) {
1055 array.add_element (Json.gobject_serialize (text_edit));
1060 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1061 error ("deserialization not supported");
1065 public abstract class CommandLike : Object, Json.Serializable {
1067 * The identifier of the actual command handler.
1069 public string command { get; set; }
1072 * Arguments that the command handler should be invoked with.
1074 public Array<Variant>? arguments { get; set; }
1076 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1077 if (property_name != "arguments" || arguments == null)
1078 return default_serialize_property (property_name, value, pspec);
1080 var array = new Json.Array ();
1081 for (int i = 0; i < arguments.length; i++)
1082 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1084 var node = new Json.Node (Json.NodeType.ARRAY);
1085 node.set_array (array);
1089 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1091 if (property_name == "arguments") {
1092 value = GLib.Value (typeof(Array));
1093 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1094 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1098 var arguments = new Array<Variant> ();
1100 property_node.get_array ().foreach_element ((array, index, element) => {
1102 arguments.append_val (Json.gvariant_deserialize (element, null));
1104 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1108 value.set_boxed (arguments);
1110 } else if (property_name == "command") {
1111 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1112 if (property_node.get_value_type () != typeof (string)) {
1114 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1118 value = property_node.get_string ();
1121 return default_deserialize_property (property_name, out value, pspec, property_node);
1126 public class ExecuteCommandParams : CommandLike {
1130 * Represents a reference to a command. Provides a title which will be used
1131 * to represent a command in the UI. Commands are identified by a string
1132 * identifier. The recommended way to handle commands is to implement their
1133 * execution on the server side if the client and server provides the
1134 * corresponding capabilities. Alternatively the tool extension code could
1135 * handle the command. The protocol currently doesn’t specify a set of
1136 * well-known commands.
1138 public class Command : CommandLike {
1140 * The title of the command, like `save`.
1142 public string title { get; set; }
1146 * A code lens represents a command that should be shown along with
1147 * source text, like the number of references, a way to run tests, etc.
1149 * A code lens is _unresolved_ when no command is associated to it. For
1150 * performance reasons the creation of a code lens and resolving should be done
1153 public class CodeLens : Object {
1155 * The range in which this code lens is valid. Should only span a single
1158 public Range range { get; set; }
1161 * The command this code lens represents.
1163 public Command? command { get; set; }
1166 public class DocumentRangeFormattingParams : Object {
1167 public TextDocumentIdentifier textDocument { get; set; }
1168 public Range? range { get; set; }
1169 public FormattingOptions options { get; set; }
1172 public class FormattingOptions : Object {
1173 public uint tabSize { get; set; }
1174 public bool insertSpaces { get; set; }
1175 public bool trimTrailingWhitespace { get; set; }
1176 public bool insertFinalNewline { get; set; }
1177 public bool trimFinalNewlines { get; set; }
1180 public class CodeActionParams : Object {
1181 public TextDocumentIdentifier textDocument { get; set; }
1182 public Range range { get; set; }
1183 public CodeActionContext context { get; set; }
1187 public class CodeActionContext : Object, Json.Serializable {
1188 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1189 public string[]? only { get; set; }
1191 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1192 if (property_name != "diagnostics")
1193 return default_deserialize_property (property_name, out value, pspec, property_node);
1194 var diags = new Gee.ArrayList<Diagnostic> ();
1195 property_node.get_array ().foreach_element ((array, index, element) => {
1197 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1199 warning ("argument %u could not be deserialized: %s", index, e.message);
1209 public class Diagnostics : Object, Json.Serializable
1211 public Diagnostics()
1213 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1218 public string uri { get; set; }
1220 public int version { get; set; default = 0; }
1221 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1223 public string filename {
1225 return File.new_for_uri (this.uri).get_path();
1230 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1231 if (property_name == "diagnostics") {
1232 val = GLib.Value (typeof(Gee.ArrayList));
1233 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1236 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1237 val.set_object(diags);
1238 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1244 property_node.get_array ().foreach_element ((array, index, element) => {
1246 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1248 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1251 val.set_object(diags);
1256 return default_deserialize_property (property_name, out val, pspec, property_node);
1264 public class CodeAction : Object, Json.Serializable {
1265 public string title { get; set; }
1266 public string? kind { get; set; }
1267 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1268 public bool isPreferred { get; set; }
1269 public WorkspaceEdit? edit { get; set; }
1270 public Command? command { get; set; }
1271 public Object? data { get; set; }
1273 protected void add_diagnostic (Diagnostic diag) {
1274 if (diagnostics == null)
1275 diagnostics = new Gee.ArrayList<Diagnostic> ();
1276 diagnostics.add (diag);
1279 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1280 if (property_name != "diagnostics")
1281 return default_serialize_property (property_name, value, pspec);
1283 var array = new Json.Array ();
1284 if (diagnostics != null)
1285 foreach (var text_edit in diagnostics)
1286 array.add_element (Json.gobject_serialize (text_edit));
1287 return new Json.Node.alloc ().init_array (array);
1291 public class WorkspaceEdit : Object, Json.Serializable {
1292 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1294 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1295 if (property_name != "documentChanges")
1296 return default_serialize_property (property_name, value, pspec);
1298 var node = new Json.Node (Json.NodeType.ARRAY);
1299 node.init_array (new Json.Array ());
1300 if (documentChanges != null) {
1301 var array = node.get_array ();
1302 foreach (var text_edit in documentChanges) {
1303 array.add_element (Json.gobject_serialize (text_edit));
1311 public enum SymbolTags {
1316 public class CallHierarchyItem : Object, Json.Serializable {
1317 public string name { get; set; }
1318 public SymbolKind kind { get; set; }
1319 public SymbolTags tags { get; set; }
1320 public string? detail { get; set; }
1321 public string uri { get; set; }
1322 public Range range { get; set; }
1323 public Range selectionRange { get; set; }
1325 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1326 if (property_name != "tags")
1327 return default_serialize_property (property_name, value, pspec);
1328 var array = new Json.Array ();
1329 if (SymbolTags.DEPRECATED in tags)
1330 array.add_int_element (SymbolTags.DEPRECATED);
1331 return new Json.Node.alloc ().init_array (array);
1334 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1335 this.name = symbol.get_full_name ();
1336 if (symbol is Vala.Method) {
1337 if (symbol.parent_symbol is Vala.Namespace)
1338 this.kind = SymbolKind.Function;
1340 this.kind = SymbolKind.Method;
1341 } else if (symbol is Vala.Signal) {
1342 this.kind = SymbolKind.Event;
1343 } else if (symbol is Vala.Constructor) {
1344 this.kind = SymbolKind.Constructor;
1346 this.kind = SymbolKind.Method;
1348 var version = symbol.get_attribute ("Version");
1349 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1350 this.tags |= SymbolTags.DEPRECATED;
1352 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1353 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1354 this.range = new Range.from_sourceref (symbol.source_reference);
1355 if (symbol.comment != null)
1356 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1357 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1358 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1359 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1364 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1366 * The method that calls the query method.
1368 public CallHierarchyItem from { get; set; }
1371 * The ranges at which the query method is called by `from`.
1373 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1375 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1376 if (property_name == "from")
1377 return default_serialize_property (property_name, value, pspec);
1378 var array = new Json.Array ();
1379 foreach (var range in fromRanges)
1380 array.add_element (Json.gobject_serialize (range));
1381 return new Json.Node.alloc ().init_array (array);
1385 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1387 * The method that the query method calls.
1389 public CallHierarchyItem to { get; set; }
1392 * The ranges at which the method is called by the query method.
1394 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1396 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1397 if (property_name == "to")
1398 return default_serialize_property (property_name, value, pspec);
1399 var array = new Json.Array ();
1400 foreach (var range in fromRanges)
1401 array.add_element (Json.gobject_serialize (range));
1402 return new Json.Node.alloc ().init_array (array);
1406 public class InlayHintParams : Json.Serializable, Object {
1407 public TextDocumentIdentifier textDocument { get; set; }
1408 public Range range { get; set; }
1411 public enum InlayHintKind {
1417 public class InlayHint : Object {
1418 public Position position { get; set; }
1419 public string label { get; set; }
1420 public InlayHintKind kind { get; set; }
1421 public string? tooltip { get; set; }
1422 public bool paddingLeft { get; set; }
1423 public bool paddingRight { get; set; }
1426 public class TypeHierarchyItem : Object, Json.Serializable {
1428 * The name of this item
1430 public string name { get; set; }
1433 * The kind of this item
1435 public SymbolKind kind { get; set; }
1438 * Tags for this item
1440 public SymbolTags tags { get; set; }
1443 * More detail for this item, e.g. the signature of a function.
1445 public string? detail { get; set; }
1448 * The resource identifier of this item.
1450 public string uri { get; set; }
1453 * The range enclosing this symbol not including leading/trailing
1454 * whitespace, but everything else, e.g. comments and code.
1456 public Range range { get; set; }
1459 * The range that should be selected and revealed when this symbol
1460 * is being picked, e.g. the name of a function. Must be contained
1461 * by {@link TypeHierarchyItem.range}
1463 public Range selectionRange { get; set; }
1465 private TypeHierarchyItem () {}
1467 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1468 this.name = symbol.get_full_name ();
1469 if (symbol is Vala.Class)
1470 this.kind = SymbolKind.Class;
1471 else if (symbol is Vala.Delegate)
1472 this.kind = SymbolKind.Interface;
1473 else if (symbol is Vala.Enum)
1474 this.kind = SymbolKind.Enum;
1475 else if (symbol is Vala.ErrorCode)
1476 this.kind = SymbolKind.EnumMember;
1477 else if (symbol is Vala.ErrorDomain)
1478 this.kind = SymbolKind.Enum;
1479 else if (symbol is Vala.Interface)
1480 this.kind = SymbolKind.Interface;
1481 else if (symbol is Vala.Struct)
1482 this.kind = SymbolKind.Struct;
1483 else if (symbol is Vala.TypeParameter)
1484 this.kind = SymbolKind.TypeParameter;
1486 this.kind = SymbolKind.Module;
1487 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1490 var version = symbol.get_attribute ("Version");
1491 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1492 this.tags |= SymbolTags.DEPRECATED;
1494 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1495 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1496 this.range = new Range.from_sourceref (symbol.source_reference);
1497 this.selectionRange = this.range;
1499 // widen range to include all members
1500 if (symbol is Vala.ObjectTypeSymbol) {
1501 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1502 if (member.source_reference != null)
1503 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1505 } else if (symbol is Vala.Enum) {
1506 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1507 if (member.source_reference != null)
1508 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1510 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1511 if (method.source_reference != null)
1512 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1514 } else if (symbol is Vala.ErrorDomain) {
1515 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1516 if (member.source_reference != null)
1517 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1519 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1520 if (method.source_reference != null)
1521 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1523 } else if (symbol is Vala.Struct) {
1524 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1525 if (field.source_reference != null)
1526 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1528 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1529 if (method.source_reference != null)
1530 this.range = this.range.union (new Range.from_sourceref (method.source_reference));