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; }
341 public SymbolKind kind { get; set; }
342 public bool deprecated { get; set; }
343 private Range? _initial_range;
346 if (_initial_range == null)
347 _initial_range = new Range.from_sourceref (children.first ()._source_reference);
349 return children.fold<Range> ((child, current_range) => current_range.union (child.range), _initial_range);
352 public Range selectionRange { get; set; }
353 public Gee.List<DocumentSymbol> children { get; private set; default = new Gee.LinkedList<DocumentSymbol> (); }
354 public string? parent_name;
356 private DocumentSymbol () {}
359 * @param type the data type containing this symbol, if there was one (not available for Namespaces, for example)
360 * @param sym the symbol
363 public DocumentSymbol.from_vala_symbol (Vala.DataType? type, Vala.Symbol sym, SymbolKind kind) {
364 this.parent_name = sym.parent_symbol != null ? sym.parent_symbol.name : null;
365 this._initial_range = new Range.from_sourceref (sym.source_reference);
366 if (sym is Vala.Subroutine) {
367 var sub = (Vala.Subroutine) sym;
368 var body_sref = sub.body != null ? sub.body.source_reference : null;
369 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
370 // body_sref != null ? body_sref.to_string () : null);
371 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
372 val = GLib.Value (typeof(Gee.ArrayList)); body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
373 this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
376 this.name = sym.name;
377 this.detail = Vls.CodeHelp.get_symbol_representation (type, sym, null, false);
379 this.selectionRange = new Range.from_sourceref (sym.source_reference);
380 this.deprecated = sym.version.deprecated;
383 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
384 base.set_property (pspec.get_name (), value);
387 public new Value Json.Serializable.get_property (ParamSpec pspec) {
388 Value val = Value (pspec.value_type);
389 base.get_property (pspec.get_name (), ref val);
393 public unowned ParamSpec? find_property (string name) {
394 return this.get_class ().find_property (name);
397 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
398 if (property_name != "children")
399 return default_serialize_property (property_name, value, pspec);
400 var node = new Json.Node (Json.NodeType.ARRAY);
401 node.init_array (new Json.Array ());
402 var array = node.get_array ();
403 foreach (var child in children)
404 array.add_element (Json.gobject_serialize (child));
408 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
411 if (property_name != "children") {
412 return default_deserialize_property (property_name, out value, pspec, property_node);
414 value = GLib.Value (typeof(Gee.ArrayList));
415 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
416 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
420 var arguments = new Gee.ArrayList<DocumentSymbol>();
422 property_node.get_array ().foreach_element ((array, index, element) => {
424 var add= Json.gobject_deserialize ( typeof (DocumentSymbol), array.get_element(index)) as DocumentSymbol;
430 value.set_object (arguments);
435 public class SymbolInformation : Object {
436 public string name { get; set; }
437 public SymbolKind kind { get; set; }
438 public Location location { get; set; }
439 public string? containerName { get; set; }
441 public SymbolInformation.from_document_symbol (DocumentSymbol dsym, string uri) {
442 this.name = dsym.name;
443 this.kind = dsym.kind;
444 this.location = new Location (uri, dsym.range);
445 this.containerName = dsym.parent_name;
449 [CCode (default_value = "LSP_SYMBOL_KIND_Variable")]
450 public enum SymbolKind {
479 public class CompletionList : Object, Json.Serializable {
480 public bool isIncomplete { get; set; }
481 public Gee.List<CompletionItem> items { get; private set; default = new Gee.LinkedList<CompletionItem> (); }
483 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
484 base.set_property (pspec.get_name (), value);
487 public new Value Json.Serializable.get_property (ParamSpec pspec) {
488 Value val = Value(pspec.value_type);
489 base.get_property (pspec.get_name (), ref val);
493 public unowned ParamSpec? find_property (string name) {
494 return this.get_class ().find_property (name);
497 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
498 if (property_name != "items")
499 return default_serialize_property (property_name, value, pspec);
500 var node = new Json.Node (Json.NodeType.ARRAY);
501 node.init_array (new Json.Array ());
502 var array = node.get_array ();
503 foreach (var child in items)
504 array.add_element (Json.gobject_serialize (child));
508 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
509 error ("deserialization not supported");
513 [CCode (default_value = "LSP_COMPLETION_TRIGGER_KIND_Invoked")]
514 public enum CompletionTriggerKind {
516 * Completion was triggered by typing an identifier (24x7 code
517 * complete), manual invocation (e.g Ctrl+Space) or via API.
522 * Completion was triggered by a trigger character specified by
523 * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
525 TriggerCharacter = 2,
528 * Completion was re-triggered as the current completion list is incomplete.
530 TriggerForIncompleteCompletions = 3
533 public class CompletionContext : Object {
534 public CompletionTriggerKind triggerKind { get; set;}
535 public string? triggerCharacter { get; set; }
538 public class CompletionParams : TextDocumentPositionParams {
540 * The completion context. This is only available if the client specifies
541 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
543 public CompletionContext? context { get; set; }
546 public enum CompletionItemTag {
547 // Render a completion as obsolete, usually using a strike-out.
551 [CCode (default_value = "LSP_INSERT_TEXT_FORMAT_PlainText")]
552 public enum InsertTextFormat {
554 * The primary text to be inserted is treated as a plain string.
559 * The primary text to be inserted is treated as a snippet.
561 * A snippet can define tab stops and placeholders with `$1`, `$2`
562 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
563 * the end of the snippet. Placeholders with equal identifiers are linked,
564 * that is typing in one will update others too.
569 public class CompletionItem : Object, Gee.Hashable<CompletionItem>, Json.Serializable {
570 public string label { get; set; }
571 public CompletionItemKind kind { get; set; }
572 public string detail { get; set; }
573 public MarkupContent? documentation { get; set; }
574 public bool deprecated { get; set; }
575 public Gee.List<CompletionItemTag> tags { get; private set; default = new Gee.ArrayList<CompletionItemTag> (); }
576 public string? insertText { get; set; }
577 public InsertTextFormat insertTextFormat { get; set; default = InsertTextFormat.PlainText; }
580 private CompletionItem () {}
582 public CompletionItem.keyword (string keyword, string? insert_text = null, string? documentation = null) {
583 this.label = keyword;
584 this.kind = CompletionItemKind.Keyword;
585 this.insertText = insert_text;
586 if (insert_text != null && (insert_text.contains ("$0") || insert_text.contains ("${0")))
587 this.insertTextFormat = InsertTextFormat.Snippet;
588 if (documentation != null)
589 this.documentation = new MarkupContent.from_plaintext (documentation);
590 this._hash = @"$label $kind".hash ();
594 * A completion suggestion from an existing Vala symbol.
596 * @param instance_type the parent data type of data type of the expression where this symbol appears, or null
597 * @param sym the symbol itself
598 * @param scope the scope to display this in
599 * @param kind the kind of completion to display
600 * @param documentation the documentation to display
601 * @param label_override if non-null, override the displayed symbol name with this
604 public CompletionItem.from_symbol (Vala.DataType? instance_type, Vala.Symbol sym, Vala.Scope? scope,
605 CompletionItemKind kind,
606 Vls.DocComment? documentation, string? label_override = null) {
607 this.label = label_override ?? sym.name;
609 this.detail = Vls.CodeHelp.get_symbol_representation (instance_type, sym, scope, true, null, label_override, false);
610 this._hash = @"$label $kind".hash ();
612 if (documentation != null)
613 this.documentation = new MarkupContent.from_markdown (documentation.body);
615 var version = sym.get_attribute ("Version");
616 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
617 this.tags.add (CompletionItemTag.Deprecated);
618 this.deprecated = true;
623 * A completion suggestion from a data type and a synthetic symbol name.
625 * @param symbol_type the data type of the symbol
626 * @param symbol_name the name of the synthetic symbol
627 * @param scope the scope that this completion item is displayed in, or null
628 * @param kind the type of completion to display
629 * @param documentation the documentation for this symbol, or null
632 public CompletionItem.from_synthetic_symbol (Vala.DataType symbol_type, string symbol_name, Vala.Scope? scope,
633 CompletionItemKind kind, Vls.DocComment? documentation) {
634 this.label = symbol_name;
636 this.detail = @"$(Vls.CodeHelp.get_symbol_representation (symbol_type, null, scope, true, null, null, false)) $symbol_name";
637 this._hash = @"$label $kind".hash ();
639 if (documentation != null)
640 this.documentation = new MarkupContent.from_markdown (documentation.body);
644 public CompletionItem.from_unimplemented_symbol (Vala.Symbol sym,
645 string label, CompletionItemKind kind,
647 Vls.DocComment? documentation) {
650 this.insertText = insert_text;
651 if (insert_text.contains ("$0") || insert_text.contains ("${0"))
652 this.insertTextFormat = InsertTextFormat.Snippet;
653 this._hash = @"$label $kind".hash ();
654 if (documentation != null)
655 this.documentation = new MarkupContent.from_markdown (documentation.body);
659 public uint hash () {
663 public bool equal_to (CompletionItem other) {
664 return other.label == this.label && other.kind == this.kind;
667 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
668 base.set_property (pspec.get_name (), value);
671 public new Value Json.Serializable.get_property (ParamSpec pspec) {
672 Value val = Value(pspec.value_type);
673 base.get_property (pspec.get_name (), ref val);
677 public unowned ParamSpec? find_property (string name) {
678 return this.get_class ().find_property (name);
681 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
682 if (property_name != "tags")
683 return default_serialize_property (property_name, value, pspec);
685 var node = new Json.Node (Json.NodeType.ARRAY);
686 node.init_array (new Json.Array ());
687 var array = node.get_array ();
688 foreach (var tag in this.tags) {
689 array.add_int_element (tag);
694 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
696 if (property_name != "tags") {
697 return default_deserialize_property (property_name, out value, pspec, property_node);
699 value = GLib.Value (typeof(Gee.ArrayList));
700 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
701 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
705 var arguments = new Gee.ArrayList<CompletionItemTag>();
707 property_node.get_array ().foreach_element ((array, index, element) => {
709 arguments.add ((CompletionItemTag) Json.gvariant_deserialize (element, null).get_int32() );
711 warning ("argument %u to command could not be deserialized: %s", index, e.message);
715 value.set_object (arguments);
720 public class MarkupContent : Object {
721 public string kind { get; set; }
722 public string value { get; set; }
724 private MarkupContent () {}
727 * Create a MarkupContent with plain text.
729 public MarkupContent.from_plaintext (string doc) {
730 this.kind = "plaintext";
735 * Create a MarkupContent with markdown text.
737 public MarkupContent.from_markdown (string doc) {
738 this.kind = "markdown";
743 [CCode (default_value = "LSP_COMPLETION_ITEM_KIND_Text")]
744 public enum CompletionItemKind {
773 * Capabilities of the client/editor for `textDocument/documentSymbol`
775 public class DocumentSymbolCapabilities : Object {
776 public bool hierarchicalDocumentSymbolSupport { get; set; }
780 * Capabilities of the client/editor for `textDocument/rename`
782 public class RenameClientCapabilities : Object {
783 public bool prepareSupport { get; set; }
787 * Capabilities of the client/editor pertaining to language features.
789 public class TextDocumentClientCapabilities : Object {
790 public DocumentSymbolCapabilities documentSymbol { get; set; default = new DocumentSymbolCapabilities ();}
791 public RenameClientCapabilities rename { get; set; default = new RenameClientCapabilities (); }
795 * Capabilities of the client/editor.
797 public class ClientCapabilities : Object {
798 public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
801 public class InitializeParams : Object {
802 public int processId { get; set; }
803 public string? rootPath { get; set; }
804 public string? rootUri { get; set; }
805 public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
808 public class SignatureInformation : Object, Json.Serializable {
809 public string label { get; set; }
810 public MarkupContent documentation { get; set; }
812 public Gee.List<ParameterInformation> parameters { get; private set; default = new Gee.LinkedList<ParameterInformation> (); }
814 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
815 base.set_property (pspec.get_name (), value);
818 public new Value Json.Serializable.get_property (ParamSpec pspec) {
819 Value val = Value(pspec.value_type);
820 base.get_property (pspec.get_name (), ref val);
824 public unowned ParamSpec? find_property (string name) {
825 return this.get_class ().find_property (name);
828 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
829 if (property_name != "parameters")
830 return default_serialize_property (property_name, value, pspec);
831 var node = new Json.Node (Json.NodeType.ARRAY);
832 node.init_array (new Json.Array ());
833 var array = node.get_array ();
834 foreach (var child in parameters)
835 array.add_element (Json.gobject_serialize (child));
839 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
840 error ("deserialization not supported");
844 public class SignatureHelp : Object, Json.Serializable {
845 public Gee.Collection<SignatureInformation> signatures { get; set; default = new Gee.ArrayList<SignatureInformation> (); }
846 public int activeSignature { get; set; }
847 public int activeParameter { get; set; }
849 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
850 if (property_name != "signatures")
851 return default_serialize_property (property_name, value, pspec);
853 var node = new Json.Node (Json.NodeType.ARRAY);
854 node.init_array (new Json.Array ());
855 var array = node.get_array ();
856 foreach (var child in signatures)
857 array.add_element (Json.gobject_serialize (child));
861 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
862 error ("deserialization not supported");
866 public class ParameterInformation : Object {
867 public string label { get; set; }
868 public MarkupContent documentation { get; set; }
871 public class MarkedString : Object {
872 public MarkedString(string language, string value)
874 this.language = language;
876 GLib.debug("new marked string %s : %s", language, value);
878 public string language { get; set; }
879 public string value { get; set; }
882 public class Hover : Object, Json.Serializable {
883 public Gee.List<MarkedString> contents { get; set; default = new Gee.ArrayList<MarkedString> (); }
884 public Range range { get; set; }
886 public new void Json.Serializable.set_property (ParamSpec pspec, Value value) {
887 base.set_property (pspec.get_name (), value);
890 public new Value Json.Serializable.get_property (ParamSpec pspec) {
891 Value val = Value(pspec.value_type);
892 base.get_property (pspec.get_name (), ref val);
896 public unowned ParamSpec? find_property (string name) {
897 return this.get_class ().find_property (name);
900 public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) {
901 if (property_name != "contents")
902 return default_serialize_property (property_name, value, pspec);
903 var node = new Json.Node (Json.NodeType.ARRAY);
904 node.init_array (new Json.Array ());
905 var array = node.get_array ();
906 foreach (var child in contents) {
907 if (child.language != null)
908 array.add_element (Json.gobject_serialize (child));
910 array.add_element (new Json.Node (Json.NodeType.VALUE).init_string (child.value));
915 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node)
917 if (property_name == "contents") {
918 value = GLib.Value (typeof(Gee.ArrayList));
919 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
920 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
923 var contents = new Gee.ArrayList<MarkedString>();
925 property_node.get_array ().foreach_element ((array, index, element) => {
927 var add = new MarkedString(
928 array.get_object_element(index).get_string_member("language"),
929 array.get_object_element(index).get_string_member("value")
932 contents.add ( add );
934 warning ("argument %u to command could not be deserialized: %s", index, e.message);
937 value.set_object (contents);
941 return default_deserialize_property (property_name, out value, pspec, property_node);
946 * A textual edit applicable to a text document.
948 public class TextEdit : Object {
950 * The range of the text document to be manipulated. To insert
951 * text into a document create a range where ``start === end``.
953 public Range range { get; set; }
956 * The string to be inserted. For delete operations use an
959 public string newText { get; set; }
961 public TextEdit (Range range, string new_text = "") {
963 this.newText = new_text;
968 * Describes textual changes on a single text document. The text document is
969 * referred to as a {@link VersionedTextDocumentIdentifier} to allow clients to
970 * check the text document version before an edit is applied. A
971 * {@link TextDocumentEdit} describes all changes on a version ``Si`` and after they are
972 * applied move the document to version ``Si+1``. So the creator of a
973 * {@link TextDocumentEdit} doesn’t need to sort the array of edits or do any kind
974 * of ordering. However the edits must be non overlapping.
976 public class TextDocumentEdit : Object, Json.Serializable {
978 * The text document to change.
980 public VersionedTextDocumentIdentifier textDocument { get; set; }
983 * The edits to be applied.
985 public Gee.ArrayList<TextEdit> edits { get; set; default = new Gee.ArrayList<TextEdit> (); }
987 public TextDocumentEdit (VersionedTextDocumentIdentifier text_document) {
988 this.textDocument = text_document;
991 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
992 if (property_name != "edits")
993 return default_serialize_property (property_name, value, pspec);
995 var node = new Json.Node (Json.NodeType.ARRAY);
996 node.init_array (new Json.Array ());
997 var array = node.get_array ();
998 foreach (var text_edit in edits) {
999 array.add_element (Json.gobject_serialize (text_edit));
1004 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) {
1005 error ("deserialization not supported");
1009 public abstract class CommandLike : Object, Json.Serializable {
1011 * The identifier of the actual command handler.
1013 public string command { get; set; }
1016 * Arguments that the command handler should be invoked with.
1018 public Array<Variant>? arguments { get; set; }
1020 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1021 if (property_name != "arguments" || arguments == null)
1022 return default_serialize_property (property_name, value, pspec);
1024 var array = new Json.Array ();
1025 for (int i = 0; i < arguments.length; i++)
1026 array.add_element (Json.gvariant_serialize (arguments.index (i)));
1028 var node = new Json.Node (Json.NodeType.ARRAY);
1029 node.set_array (array);
1033 public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node)
1035 if (property_name == "arguments") {
1036 value = GLib.Value (typeof(Array));
1037 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1038 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1042 var arguments = new Array<Variant> ();
1044 property_node.get_array ().foreach_element ((array, index, element) => {
1046 arguments.append_val (Json.gvariant_deserialize (element, null));
1048 warning ("argument %u to command could not be deserialized: %s", index, e.message);
1052 value.set_boxed (arguments);
1054 } else if (property_name == "command") {
1055 // workaround for json-glib < 1.5.2 (Ubuntu 20.04 / eOS 6)
1056 if (property_node.get_value_type () != typeof (string)) {
1058 warning ("unexpected property node type for 'commands' %s", property_node.get_node_type ().to_string ());
1062 value = property_node.get_string ();
1065 return default_deserialize_property (property_name, out value, pspec, property_node);
1070 public class ExecuteCommandParams : CommandLike {
1074 * Represents a reference to a command. Provides a title which will be used
1075 * to represent a command in the UI. Commands are identified by a string
1076 * identifier. The recommended way to handle commands is to implement their
1077 * execution on the server side if the client and server provides the
1078 * corresponding capabilities. Alternatively the tool extension code could
1079 * handle the command. The protocol currently doesn’t specify a set of
1080 * well-known commands.
1082 public class Command : CommandLike {
1084 * The title of the command, like `save`.
1086 public string title { get; set; }
1090 * A code lens represents a command that should be shown along with
1091 * source text, like the number of references, a way to run tests, etc.
1093 * A code lens is _unresolved_ when no command is associated to it. For
1094 * performance reasons the creation of a code lens and resolving should be done
1097 public class CodeLens : Object {
1099 * The range in which this code lens is valid. Should only span a single
1102 public Range range { get; set; }
1105 * The command this code lens represents.
1107 public Command? command { get; set; }
1110 public class DocumentRangeFormattingParams : Object {
1111 public TextDocumentIdentifier textDocument { get; set; }
1112 public Range? range { get; set; }
1113 public FormattingOptions options { get; set; }
1116 public class FormattingOptions : Object {
1117 public uint tabSize { get; set; }
1118 public bool insertSpaces { get; set; }
1119 public bool trimTrailingWhitespace { get; set; }
1120 public bool insertFinalNewline { get; set; }
1121 public bool trimFinalNewlines { get; set; }
1124 public class CodeActionParams : Object {
1125 public TextDocumentIdentifier textDocument { get; set; }
1126 public Range range { get; set; }
1127 public CodeActionContext context { get; set; }
1131 public class CodeActionContext : Object, Json.Serializable {
1132 public Gee.List<Diagnostic> diagnostics { get; set; default = new Gee.ArrayList<Diagnostic> (); }
1133 public string[]? only { get; set; }
1135 public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) {
1136 if (property_name != "diagnostics")
1137 return default_deserialize_property (property_name, out value, pspec, property_node);
1138 var diags = new Gee.ArrayList<Diagnostic> ();
1139 property_node.get_array ().foreach_element ((array, index, element) => {
1141 diags.add (Vls.Util.parse_variant<Diagnostic> (Json.gvariant_deserialize (element, null)));
1143 warning ("argument %u could not be deserialized: %s", index, e.message);
1153 public class Diagnostics : Object, Json.Serializable
1155 public Diagnostics()
1157 this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
1162 public string uri { get; set; }
1164 public int version { get; set; default = 0; }
1165 public Gee.ArrayList<Diagnostic>? diagnostics { get; set; }
1167 public string filename {
1169 return File.new_for_uri (this.uri).get_path();
1174 public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
1175 if (property_name == "diagnostics") {
1176 val = GLib.Value (typeof(Gee.ArrayList));
1177 var diags = new Gee.ArrayList<Diagnostic> ((a,b) => {
1180 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
1181 val.set_object(diags);
1182 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
1188 property_node.get_array ().foreach_element ((array, index, element) => {
1190 diags.add (Json.gobject_deserialize (typeof (Lsp.Diagnostic), element) as Diagnostic );
1192 //warning ("argument %u to command could not be deserialized: %s", index, e.message);
1195 val.set_object(diags);
1200 return default_deserialize_property (property_name, out val, pspec, property_node);
1208 public class CodeAction : Object, Json.Serializable {
1209 public string title { get; set; }
1210 public string? kind { get; set; }
1211 public Gee.Collection<Diagnostic>? diagnostics { get; set; }
1212 public bool isPreferred { get; set; }
1213 public WorkspaceEdit? edit { get; set; }
1214 public Command? command { get; set; }
1215 public Object? data { get; set; }
1217 protected void add_diagnostic (Diagnostic diag) {
1218 if (diagnostics == null)
1219 diagnostics = new Gee.ArrayList<Diagnostic> ();
1220 diagnostics.add (diag);
1223 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1224 if (property_name != "diagnostics")
1225 return default_serialize_property (property_name, value, pspec);
1227 var array = new Json.Array ();
1228 if (diagnostics != null)
1229 foreach (var text_edit in diagnostics)
1230 array.add_element (Json.gobject_serialize (text_edit));
1231 return new Json.Node.alloc ().init_array (array);
1235 public class WorkspaceEdit : Object, Json.Serializable {
1236 public Gee.List<TextDocumentEdit>? documentChanges { get; set; }
1238 public Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1239 if (property_name != "documentChanges")
1240 return default_serialize_property (property_name, value, pspec);
1242 var node = new Json.Node (Json.NodeType.ARRAY);
1243 node.init_array (new Json.Array ());
1244 if (documentChanges != null) {
1245 var array = node.get_array ();
1246 foreach (var text_edit in documentChanges) {
1247 array.add_element (Json.gobject_serialize (text_edit));
1255 public enum SymbolTags {
1260 public class CallHierarchyItem : Object, Json.Serializable {
1261 public string name { get; set; }
1262 public SymbolKind kind { get; set; }
1263 public SymbolTags tags { get; set; }
1264 public string? detail { get; set; }
1265 public string uri { get; set; }
1266 public Range range { get; set; }
1267 public Range selectionRange { get; set; }
1269 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1270 if (property_name != "tags")
1271 return default_serialize_property (property_name, value, pspec);
1272 var array = new Json.Array ();
1273 if (SymbolTags.DEPRECATED in tags)
1274 array.add_int_element (SymbolTags.DEPRECATED);
1275 return new Json.Node.alloc ().init_array (array);
1278 public CallHierarchyItem.from_symbol (Vala.Symbol symbol) {
1279 this.name = symbol.get_full_name ();
1280 if (symbol is Vala.Method) {
1281 if (symbol.parent_symbol is Vala.Namespace)
1282 this.kind = SymbolKind.Function;
1284 this.kind = SymbolKind.Method;
1285 } else if (symbol is Vala.Signal) {
1286 this.kind = SymbolKind.Event;
1287 } else if (symbol is Vala.Constructor) {
1288 this.kind = SymbolKind.Constructor;
1290 this.kind = SymbolKind.Method;
1292 var version = symbol.get_attribute ("Version");
1293 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1294 this.tags |= SymbolTags.DEPRECATED;
1296 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1297 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1298 this.range = new Range.from_sourceref (symbol.source_reference);
1299 if (symbol.comment != null)
1300 this.range = new Range.from_sourceref (symbol.comment.source_reference).union (this.range);
1301 if (symbol is Vala.Subroutine && ((Vala.Subroutine)symbol).body != null)
1302 this.range = new Range.from_sourceref (((Vala.Subroutine)symbol).body.source_reference).union (this.range);
1303 this.selectionRange = new Range.from_sourceref (symbol.source_reference);
1308 public class CallHierarchyIncomingCall : Json.Serializable, Object {
1310 * The method that calls the query method.
1312 public CallHierarchyItem from { get; set; }
1315 * The ranges at which the query method is called by `from`.
1317 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1319 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1320 if (property_name == "from")
1321 return default_serialize_property (property_name, value, pspec);
1322 var array = new Json.Array ();
1323 foreach (var range in fromRanges)
1324 array.add_element (Json.gobject_serialize (range));
1325 return new Json.Node.alloc ().init_array (array);
1329 public class CallHierarchyOutgoingCall : Json.Serializable, Object {
1331 * The method that the query method calls.
1333 public CallHierarchyItem to { get; set; }
1336 * The ranges at which the method is called by the query method.
1338 public Gee.ArrayList<Range> fromRanges { get; set; default = new Gee.ArrayList<Range> (); }
1340 public override Json.Node serialize_property (string property_name, GLib.Value value, GLib.ParamSpec pspec) {
1341 if (property_name == "to")
1342 return default_serialize_property (property_name, value, pspec);
1343 var array = new Json.Array ();
1344 foreach (var range in fromRanges)
1345 array.add_element (Json.gobject_serialize (range));
1346 return new Json.Node.alloc ().init_array (array);
1350 public class InlayHintParams : Json.Serializable, Object {
1351 public TextDocumentIdentifier textDocument { get; set; }
1352 public Range range { get; set; }
1355 public enum InlayHintKind {
1361 public class InlayHint : Object {
1362 public Position position { get; set; }
1363 public string label { get; set; }
1364 public InlayHintKind kind { get; set; }
1365 public string? tooltip { get; set; }
1366 public bool paddingLeft { get; set; }
1367 public bool paddingRight { get; set; }
1370 public class TypeHierarchyItem : Object, Json.Serializable {
1372 * The name of this item
1374 public string name { get; set; }
1377 * The kind of this item
1379 public SymbolKind kind { get; set; }
1382 * Tags for this item
1384 public SymbolTags tags { get; set; }
1387 * More detail for this item, e.g. the signature of a function.
1389 public string? detail { get; set; }
1392 * The resource identifier of this item.
1394 public string uri { get; set; }
1397 * The range enclosing this symbol not including leading/trailing
1398 * whitespace, but everything else, e.g. comments and code.
1400 public Range range { get; set; }
1403 * The range that should be selected and revealed when this symbol
1404 * is being picked, e.g. the name of a function. Must be contained
1405 * by {@link TypeHierarchyItem.range}
1407 public Range selectionRange { get; set; }
1409 private TypeHierarchyItem () {}
1411 public TypeHierarchyItem.from_symbol (Vala.TypeSymbol symbol) {
1412 this.name = symbol.get_full_name ();
1413 if (symbol is Vala.Class)
1414 this.kind = SymbolKind.Class;
1415 else if (symbol is Vala.Delegate)
1416 this.kind = SymbolKind.Interface;
1417 else if (symbol is Vala.Enum)
1418 this.kind = SymbolKind.Enum;
1419 else if (symbol is Vala.ErrorCode)
1420 this.kind = SymbolKind.EnumMember;
1421 else if (symbol is Vala.ErrorDomain)
1422 this.kind = SymbolKind.Enum;
1423 else if (symbol is Vala.Interface)
1424 this.kind = SymbolKind.Interface;
1425 else if (symbol is Vala.Struct)
1426 this.kind = SymbolKind.Struct;
1427 else if (symbol is Vala.TypeParameter)
1428 this.kind = SymbolKind.TypeParameter;
1430 this.kind = SymbolKind.Module;
1431 warning ("unexpected symbol kind in type hierarchy: `%s'", symbol.type_name);
1434 var version = symbol.get_attribute ("Version");
1435 if (version != null && (version.get_bool ("deprecated") || version.get_string ("deprecated_since") != null)) {
1436 this.tags |= SymbolTags.DEPRECATED;
1438 this.detail = Vls.CodeHelp.get_symbol_representation (null, symbol, null, true);
1439 this.uri = File.new_for_commandline_arg (symbol.source_reference.file.filename).get_uri ();
1440 this.range = new Range.from_sourceref (symbol.source_reference);
1441 this.selectionRange = this.range;
1443 // widen range to include all members
1444 if (symbol is Vala.ObjectTypeSymbol) {
1445 foreach (var member in ((Vala.ObjectTypeSymbol)symbol).get_members ()) {
1446 if (member.source_reference != null)
1447 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1449 } else if (symbol is Vala.Enum) {
1450 foreach (var member in ((Vala.Enum)symbol).get_values ()) {
1451 if (member.source_reference != null)
1452 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1454 foreach (var method in ((Vala.Enum)symbol).get_methods ()) {
1455 if (method.source_reference != null)
1456 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1458 } else if (symbol is Vala.ErrorDomain) {
1459 foreach (var member in ((Vala.ErrorDomain)symbol).get_codes ()) {
1460 if (member.source_reference != null)
1461 this.range = this.range.union (new Range.from_sourceref (member.source_reference));
1463 foreach (var method in ((Vala.ErrorDomain)symbol).get_methods ()) {
1464 if (method.source_reference != null)
1465 this.range = this.range.union (new Range.from_sourceref (method.source_reference));
1467 } else if (symbol is Vala.Struct) {
1468 foreach (var field in ((Vala.Struct)symbol).get_fields ()) {
1469 if (field.source_reference != null)
1470 this.range = this.range.union (new Range.from_sourceref (field.source_reference));
1472 foreach (var method in ((Vala.Struct)symbol).get_methods ()) {
1473 if (method.source_reference != null)
1474 this.range = this.range.union (new Range.from_sourceref (method.source_reference));