|
@@ -46,11 +46,11 @@ struct TextDocumentIdentifier {
|
|
|
*/
|
|
|
DocumentUri uri;
|
|
|
|
|
|
- void load(const Dictionary &p_params) {
|
|
|
+ _FORCE_INLINE_ void load(const Dictionary &p_params) {
|
|
|
uri = p_params["uri"];
|
|
|
}
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["uri"] = uri;
|
|
|
return dict;
|
|
@@ -78,12 +78,12 @@ struct Position {
|
|
|
*/
|
|
|
int character = 0;
|
|
|
|
|
|
- void load(const Dictionary &p_params) {
|
|
|
+ _FORCE_INLINE_ void load(const Dictionary &p_params) {
|
|
|
line = p_params["line"];
|
|
|
character = p_params["character"];
|
|
|
}
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["line"] = line;
|
|
|
dict["character"] = character;
|
|
@@ -107,12 +107,12 @@ struct Range {
|
|
|
*/
|
|
|
Position end;
|
|
|
|
|
|
- void load(const Dictionary &p_params) {
|
|
|
+ _FORCE_INLINE_ void load(const Dictionary &p_params) {
|
|
|
start.load(p_params["start"]);
|
|
|
end.load(p_params["end"]);
|
|
|
}
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["start"] = start.to_json();
|
|
|
dict["end"] = end.to_json();
|
|
@@ -127,12 +127,12 @@ struct Location {
|
|
|
DocumentUri uri;
|
|
|
Range range;
|
|
|
|
|
|
- void load(const Dictionary &p_params) {
|
|
|
+ _FORCE_INLINE_ void load(const Dictionary &p_params) {
|
|
|
uri = p_params["uri"];
|
|
|
range.load(p_params["range"]);
|
|
|
}
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["uri"] = uri;
|
|
|
dict["range"] = range.to_json();
|
|
@@ -186,12 +186,12 @@ struct TextDocumentPositionParams {
|
|
|
*/
|
|
|
Position position;
|
|
|
|
|
|
- void load(const Dictionary &p_params) {
|
|
|
+ _FORCE_INLINE_ void load(const Dictionary &p_params) {
|
|
|
textDocument.load(p_params["textDocument"]);
|
|
|
position.load(p_params["position"]);
|
|
|
}
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["textDocument"] = textDocument.to_json();
|
|
|
dict["position"] = position.to_json();
|
|
@@ -199,6 +199,54 @@ struct TextDocumentPositionParams {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * A textual edit applicable to a text document.
|
|
|
+ */
|
|
|
+struct TextEdit {
|
|
|
+ /**
|
|
|
+ * The range of the text document to be manipulated. To insert
|
|
|
+ * text into a document create a range where start === end.
|
|
|
+ */
|
|
|
+ Range range;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The string to be inserted. For delete operations use an
|
|
|
+ * empty string.
|
|
|
+ */
|
|
|
+ String newText;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Represents a reference to a command.
|
|
|
+ * Provides a title which will be used to represent a command in the UI.
|
|
|
+ * Commands are identified by a string identifier.
|
|
|
+ * The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
|
|
|
+ * Alternatively the tool extension code could handle the command. The protocol currently doesn’t specify a set of well-known commands.
|
|
|
+ */
|
|
|
+struct Command {
|
|
|
+ /**
|
|
|
+ * Title of the command, like `save`.
|
|
|
+ */
|
|
|
+ String title;
|
|
|
+ /**
|
|
|
+ * The identifier of the actual command handler.
|
|
|
+ */
|
|
|
+ String command;
|
|
|
+ /**
|
|
|
+ * Arguments that the command handler should be
|
|
|
+ * invoked with.
|
|
|
+ */
|
|
|
+ Array arguments;
|
|
|
+
|
|
|
+ Dictionary to_json() const {
|
|
|
+ Dictionary dict;
|
|
|
+ dict["title"] = title;
|
|
|
+ dict["command"] = command;
|
|
|
+ if (arguments.size()) dict["arguments"] = arguments;
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
namespace TextDocumentSyncKind {
|
|
|
/**
|
|
|
* Documents should not be synced at all.
|
|
@@ -674,474 +722,471 @@ struct MarkupContent {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * A symbol kind.
|
|
|
+ * The kind of a completion entry.
|
|
|
*/
|
|
|
-namespace SymbolKind {
|
|
|
-static const int File = 1;
|
|
|
-static const int Module = 2;
|
|
|
-static const int Namespace = 3;
|
|
|
-static const int Package = 4;
|
|
|
-static const int Class = 5;
|
|
|
-static const int Method = 6;
|
|
|
-static const int Property = 7;
|
|
|
-static const int Field = 8;
|
|
|
-static const int Constructor = 9;
|
|
|
-static const int Enum = 10;
|
|
|
-static const int Interface = 11;
|
|
|
-static const int Function = 12;
|
|
|
-static const int Variable = 13;
|
|
|
-static const int Constant = 14;
|
|
|
-static const int String = 15;
|
|
|
-static const int Number = 16;
|
|
|
-static const int Boolean = 17;
|
|
|
-static const int Array = 18;
|
|
|
-static const int Object = 19;
|
|
|
-static const int Key = 20;
|
|
|
-static const int Null = 21;
|
|
|
-static const int EnumMember = 22;
|
|
|
-static const int Struct = 23;
|
|
|
-static const int Event = 24;
|
|
|
-static const int Operator = 25;
|
|
|
-static const int TypeParameter = 26;
|
|
|
-}; // namespace SymbolKind
|
|
|
+namespace CompletionItemKind {
|
|
|
+static const int Text = 1;
|
|
|
+static const int Method = 2;
|
|
|
+static const int Function = 3;
|
|
|
+static const int Constructor = 4;
|
|
|
+static const int Field = 5;
|
|
|
+static const int Variable = 6;
|
|
|
+static const int Class = 7;
|
|
|
+static const int Interface = 8;
|
|
|
+static const int Module = 9;
|
|
|
+static const int Property = 10;
|
|
|
+static const int Unit = 11;
|
|
|
+static const int Value = 12;
|
|
|
+static const int Enum = 13;
|
|
|
+static const int Keyword = 14;
|
|
|
+static const int Snippet = 15;
|
|
|
+static const int Color = 16;
|
|
|
+static const int File = 17;
|
|
|
+static const int Reference = 18;
|
|
|
+static const int Folder = 19;
|
|
|
+static const int EnumMember = 20;
|
|
|
+static const int Constant = 21;
|
|
|
+static const int Struct = 22;
|
|
|
+static const int Event = 23;
|
|
|
+static const int Operator = 24;
|
|
|
+static const int TypeParameter = 25;
|
|
|
+}; // namespace CompletionItemKind
|
|
|
|
|
|
/**
|
|
|
- * Represents information about programming constructs like variables, classes,
|
|
|
- * interfaces etc.
|
|
|
+ * Defines whether the insert text in a completion item should be interpreted as
|
|
|
+ * plain text or a snippet.
|
|
|
*/
|
|
|
-struct SymbolInformation {
|
|
|
- /**
|
|
|
- * The name of this symbol.
|
|
|
- */
|
|
|
- String name;
|
|
|
-
|
|
|
- /**
|
|
|
- * The kind of this symbol.
|
|
|
+namespace InsertTextFormat {
|
|
|
+/**
|
|
|
+ * The primary text to be inserted is treated as a plain string.
|
|
|
*/
|
|
|
- int kind = SymbolKind::File;
|
|
|
+static const int PlainText = 1;
|
|
|
|
|
|
- /**
|
|
|
- * Indicates if this symbol is deprecated.
|
|
|
+/**
|
|
|
+ * The primary text to be inserted is treated as a snippet.
|
|
|
+ *
|
|
|
+ * A snippet can define tab stops and placeholders with `$1`, `$2`
|
|
|
+ * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
|
|
|
+ * the end of the snippet. Placeholders with equal identifiers are linked,
|
|
|
+ * that is typing in one will update others too.
|
|
|
*/
|
|
|
- bool deprecated = false;
|
|
|
+static const int Snippet = 2;
|
|
|
+}; // namespace InsertTextFormat
|
|
|
|
|
|
+struct CompletionItem {
|
|
|
/**
|
|
|
- * The location of this symbol. The location's range is used by a tool
|
|
|
- * to reveal the location in the editor. If the symbol is selected in the
|
|
|
- * tool the range's start information is used to position the cursor. So
|
|
|
- * the range usually spans more then the actual symbol's name and does
|
|
|
- * normally include things like visibility modifiers.
|
|
|
- *
|
|
|
- * The range doesn't have to denote a node range in the sense of a abstract
|
|
|
- * syntax tree. It can therefore not be used to re-construct a hierarchy of
|
|
|
- * the symbols.
|
|
|
+ * The label of this completion item. By default
|
|
|
+ * also the text that is inserted when selecting
|
|
|
+ * this completion.
|
|
|
*/
|
|
|
- Location location;
|
|
|
+ String label;
|
|
|
|
|
|
/**
|
|
|
- * The name of the symbol containing this symbol. This information is for
|
|
|
- * user interface purposes (e.g. to render a qualifier in the user interface
|
|
|
- * if necessary). It can't be used to re-infer a hierarchy for the document
|
|
|
- * symbols.
|
|
|
+ * The kind of this completion item. Based of the kind
|
|
|
+ * an icon is chosen by the editor. The standardized set
|
|
|
+ * of available values is defined in `CompletionItemKind`.
|
|
|
*/
|
|
|
- String containerName;
|
|
|
-
|
|
|
- Dictionary to_json() const {
|
|
|
- Dictionary dict;
|
|
|
- dict["name"] = name;
|
|
|
- dict["kind"] = kind;
|
|
|
- dict["deprecated"] = deprecated;
|
|
|
- dict["location"] = location.to_json();
|
|
|
- dict["containerName"] = containerName;
|
|
|
- return dict;
|
|
|
- }
|
|
|
-};
|
|
|
+ int kind;
|
|
|
|
|
|
-struct DocumentedSymbolInformation : public SymbolInformation {
|
|
|
/**
|
|
|
* A human-readable string with additional information
|
|
|
+ * about this item, like type or symbol information.
|
|
|
*/
|
|
|
String detail;
|
|
|
|
|
|
/**
|
|
|
* A human-readable string that represents a doc-comment.
|
|
|
*/
|
|
|
- String documentation;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
|
|
|
- * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
|
|
|
- * e.g. the range of an identifier.
|
|
|
- */
|
|
|
-struct DocumentSymbol {
|
|
|
+ MarkupContent documentation;
|
|
|
|
|
|
/**
|
|
|
- * The name of this symbol. Will be displayed in the user interface and therefore must not be
|
|
|
- * an empty string or a string only consisting of white spaces.
|
|
|
+ * Indicates if this item is deprecated.
|
|
|
*/
|
|
|
- String name;
|
|
|
+ bool deprecated = false;
|
|
|
|
|
|
/**
|
|
|
- * More detail for this symbol, e.g the signature of a function.
|
|
|
+ * Select this item when showing.
|
|
|
+ *
|
|
|
+ * *Note* that only one completion item can be selected and that the
|
|
|
+ * tool / client decides which item that is. The rule is that the *first*
|
|
|
+ * item of those that match best is selected.
|
|
|
*/
|
|
|
- String detail;
|
|
|
+ bool preselect = false;
|
|
|
|
|
|
/**
|
|
|
- * Documentation for this symbol
|
|
|
+ * A string that should be used when comparing this item
|
|
|
+ * with other items. When `falsy` the label is used.
|
|
|
*/
|
|
|
- String documentation;
|
|
|
+ String sortText;
|
|
|
|
|
|
/**
|
|
|
- * The kind of this symbol.
|
|
|
+ * A string that should be used when filtering a set of
|
|
|
+ * completion items. When `falsy` the label is used.
|
|
|
*/
|
|
|
- int kind = SymbolKind::File;
|
|
|
+ String filterText;
|
|
|
|
|
|
/**
|
|
|
- * Indicates if this symbol is deprecated.
|
|
|
+ * A string that should be inserted into a document when selecting
|
|
|
+ * this completion. When `falsy` the label is used.
|
|
|
+ *
|
|
|
+ * The `insertText` is subject to interpretation by the client side.
|
|
|
+ * Some tools might not take the string literally. For example
|
|
|
+ * VS Code when code complete is requested in this example `con<cursor position>`
|
|
|
+ * and a completion item with an `insertText` of `console` is provided it
|
|
|
+ * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
|
|
|
+ * since it avoids additional client side interpretation.
|
|
|
+ *
|
|
|
+ * @deprecated Use textEdit instead.
|
|
|
*/
|
|
|
- bool deprecated = false;
|
|
|
+ String insertText;
|
|
|
|
|
|
/**
|
|
|
- * The range enclosing this symbol not including leading/trailing whitespace but everything else
|
|
|
- * like comments. This information is typically used to determine if the clients cursor is
|
|
|
- * inside the symbol to reveal in the symbol in the UI.
|
|
|
+ * The format of the insert text. The format applies to both the `insertText` property
|
|
|
+ * and the `newText` property of a provided `textEdit`.
|
|
|
*/
|
|
|
- Range range;
|
|
|
+ int insertTextFormat;
|
|
|
|
|
|
/**
|
|
|
- * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
|
|
|
- * Must be contained by the `range`.
|
|
|
+ * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
|
|
|
+ * `insertText` is ignored.
|
|
|
+ *
|
|
|
+ * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
|
|
|
+ * has been requested.
|
|
|
*/
|
|
|
- Range selectionRange;
|
|
|
-
|
|
|
- DocumentUri uri;
|
|
|
- String script_path;
|
|
|
+ TextEdit textEdit;
|
|
|
|
|
|
/**
|
|
|
- * Children of this symbol, e.g. properties of a class.
|
|
|
+ * An optional array of additional text edits that are applied when
|
|
|
+ * selecting this completion. Edits must not overlap (including the same insert position)
|
|
|
+ * with the main edit nor with themselves.
|
|
|
+ *
|
|
|
+ * Additional text edits should be used to change text unrelated to the current cursor position
|
|
|
+ * (for example adding an import statement at the top of the file if the completion item will
|
|
|
+ * insert an unqualified type).
|
|
|
*/
|
|
|
- Vector<DocumentSymbol> children;
|
|
|
+ Vector<TextEdit> additionalTextEdits;
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ /**
|
|
|
+ * An optional set of characters that when pressed while this completion is active will accept it first and
|
|
|
+ * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
|
|
|
+ * characters will be ignored.
|
|
|
+ */
|
|
|
+ Vector<String> commitCharacters;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * An optional command that is executed *after* inserting this completion. *Note* that
|
|
|
+ * additional modifications to the current document should be described with the
|
|
|
+ * additionalTextEdits-property.
|
|
|
+ */
|
|
|
+ Command command;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A data entry field that is preserved on a completion item between
|
|
|
+ * a completion and a completion resolve request.
|
|
|
+ */
|
|
|
+ Variant data;
|
|
|
+
|
|
|
+ _FORCE_INLINE_ Dictionary to_json(bool minimized = false) const {
|
|
|
Dictionary dict;
|
|
|
- dict["name"] = name;
|
|
|
- dict["detail"] = detail;
|
|
|
+ dict["label"] = label;
|
|
|
dict["kind"] = kind;
|
|
|
- dict["deprecated"] = deprecated;
|
|
|
- dict["range"] = range.to_json();
|
|
|
- dict["selectionRange"] = selectionRange.to_json();
|
|
|
- Array arr;
|
|
|
- arr.resize(children.size());
|
|
|
- for (int i = 0; i < children.size(); i++) {
|
|
|
- arr[i] = children[i].to_json();
|
|
|
+ dict["data"] = data;
|
|
|
+ if (!minimized) {
|
|
|
+ dict["insertText"] = insertText;
|
|
|
+ dict["detail"] = detail;
|
|
|
+ dict["documentation"] = documentation.to_json();
|
|
|
+ dict["deprecated"] = deprecated;
|
|
|
+ dict["preselect"] = preselect;
|
|
|
+ dict["sortText"] = sortText;
|
|
|
+ dict["filterText"] = filterText;
|
|
|
+ if (commitCharacters.size()) dict["commitCharacters"] = commitCharacters;
|
|
|
+ dict["command"] = command.to_json();
|
|
|
}
|
|
|
- dict["children"] = arr;
|
|
|
return dict;
|
|
|
}
|
|
|
|
|
|
- void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
|
|
|
- DocumentedSymbolInformation si;
|
|
|
- if (p_join_name && !p_container.empty()) {
|
|
|
- si.name = p_container + ">" + name;
|
|
|
- } else {
|
|
|
- si.name = name;
|
|
|
- }
|
|
|
- si.kind = kind;
|
|
|
- si.containerName = p_container;
|
|
|
- si.deprecated = deprecated;
|
|
|
- si.location.uri = p_uri;
|
|
|
- si.location.range = range;
|
|
|
- si.detail = detail;
|
|
|
- si.documentation = documentation;
|
|
|
- r_list.push_back(si);
|
|
|
- for (int i = 0; i < children.size(); i++) {
|
|
|
- children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- MarkupContent render() const {
|
|
|
- MarkupContent markdown;
|
|
|
- if (detail.length()) {
|
|
|
- markdown.value = "\t" + detail + "\n\n";
|
|
|
- }
|
|
|
- if (documentation.length()) {
|
|
|
- markdown.value += documentation + "\n\n";
|
|
|
- }
|
|
|
- if (script_path.length()) {
|
|
|
- markdown.value += "Defined in [" + script_path + "](" + uri + ")";
|
|
|
+ void load(const Dictionary &p_dict) {
|
|
|
+ if (p_dict.has("label")) label = p_dict["label"];
|
|
|
+ if (p_dict.has("kind")) kind = p_dict["kind"];
|
|
|
+ if (p_dict.has("detail")) detail = p_dict["detail"];
|
|
|
+ if (p_dict.has("documentation")) {
|
|
|
+ Variant doc = p_dict["documentation"];
|
|
|
+ if (doc.get_type() == Variant::STRING) {
|
|
|
+ documentation.value = doc;
|
|
|
+ } else if (doc.get_type() == Variant::DICTIONARY) {
|
|
|
+ Dictionary v = doc;
|
|
|
+ documentation.value = v["value"];
|
|
|
+ }
|
|
|
}
|
|
|
- return markdown;
|
|
|
+ if (p_dict.has("deprecated")) deprecated = p_dict["deprecated"];
|
|
|
+ if (p_dict.has("preselect")) preselect = p_dict["preselect"];
|
|
|
+ if (p_dict.has("sortText")) sortText = p_dict["sortText"];
|
|
|
+ if (p_dict.has("filterText")) filterText = p_dict["filterText"];
|
|
|
+ if (p_dict.has("insertText")) insertText = p_dict["insertText"];
|
|
|
+ if (p_dict.has("data")) data = p_dict["data"];
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * A textual edit applicable to a text document.
|
|
|
+ * Represents a collection of [completion items](#CompletionItem) to be presented
|
|
|
+ * in the editor.
|
|
|
*/
|
|
|
-struct TextEdit {
|
|
|
+struct CompletionList {
|
|
|
/**
|
|
|
- * The range of the text document to be manipulated. To insert
|
|
|
- * text into a document create a range where start === end.
|
|
|
+ * This list it not complete. Further typing should result in recomputing
|
|
|
+ * this list.
|
|
|
*/
|
|
|
- Range range;
|
|
|
+ bool isIncomplete;
|
|
|
|
|
|
/**
|
|
|
- * The string to be inserted. For delete operations use an
|
|
|
- * empty string.
|
|
|
+ * The completion items.
|
|
|
*/
|
|
|
- String newText;
|
|
|
+ Vector<CompletionItem> items;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Represents a reference to a command.
|
|
|
- * Provides a title which will be used to represent a command in the UI.
|
|
|
- * Commands are identified by a string identifier.
|
|
|
- * The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
|
|
|
- * Alternatively the tool extension code could handle the command. The protocol currently doesn’t specify a set of well-known commands.
|
|
|
+ * A symbol kind.
|
|
|
*/
|
|
|
-struct Command {
|
|
|
- /**
|
|
|
- * Title of the command, like `save`.
|
|
|
- */
|
|
|
- String title;
|
|
|
- /**
|
|
|
- * The identifier of the actual command handler.
|
|
|
- */
|
|
|
- String command;
|
|
|
- /**
|
|
|
- * Arguments that the command handler should be
|
|
|
- * invoked with.
|
|
|
- */
|
|
|
- Array arguments;
|
|
|
-
|
|
|
- Dictionary to_json() const {
|
|
|
- Dictionary dict;
|
|
|
- dict["title"] = title;
|
|
|
- dict["command"] = command;
|
|
|
- if (arguments.size()) dict["arguments"] = arguments;
|
|
|
- return dict;
|
|
|
- }
|
|
|
-};
|
|
|
+namespace SymbolKind {
|
|
|
+static const int File = 1;
|
|
|
+static const int Module = 2;
|
|
|
+static const int Namespace = 3;
|
|
|
+static const int Package = 4;
|
|
|
+static const int Class = 5;
|
|
|
+static const int Method = 6;
|
|
|
+static const int Property = 7;
|
|
|
+static const int Field = 8;
|
|
|
+static const int Constructor = 9;
|
|
|
+static const int Enum = 10;
|
|
|
+static const int Interface = 11;
|
|
|
+static const int Function = 12;
|
|
|
+static const int Variable = 13;
|
|
|
+static const int Constant = 14;
|
|
|
+static const int String = 15;
|
|
|
+static const int Number = 16;
|
|
|
+static const int Boolean = 17;
|
|
|
+static const int Array = 18;
|
|
|
+static const int Object = 19;
|
|
|
+static const int Key = 20;
|
|
|
+static const int Null = 21;
|
|
|
+static const int EnumMember = 22;
|
|
|
+static const int Struct = 23;
|
|
|
+static const int Event = 24;
|
|
|
+static const int Operator = 25;
|
|
|
+static const int TypeParameter = 26;
|
|
|
+}; // namespace SymbolKind
|
|
|
|
|
|
/**
|
|
|
- * The kind of a completion entry.
|
|
|
+ * Represents information about programming constructs like variables, classes,
|
|
|
+ * interfaces etc.
|
|
|
*/
|
|
|
-namespace CompletionItemKind {
|
|
|
-static const int Text = 1;
|
|
|
-static const int Method = 2;
|
|
|
-static const int Function = 3;
|
|
|
-static const int Constructor = 4;
|
|
|
-static const int Field = 5;
|
|
|
-static const int Variable = 6;
|
|
|
-static const int Class = 7;
|
|
|
-static const int Interface = 8;
|
|
|
-static const int Module = 9;
|
|
|
-static const int Property = 10;
|
|
|
-static const int Unit = 11;
|
|
|
-static const int Value = 12;
|
|
|
-static const int Enum = 13;
|
|
|
-static const int Keyword = 14;
|
|
|
-static const int Snippet = 15;
|
|
|
-static const int Color = 16;
|
|
|
-static const int File = 17;
|
|
|
-static const int Reference = 18;
|
|
|
-static const int Folder = 19;
|
|
|
-static const int EnumMember = 20;
|
|
|
-static const int Constant = 21;
|
|
|
-static const int Struct = 22;
|
|
|
-static const int Event = 23;
|
|
|
-static const int Operator = 24;
|
|
|
-static const int TypeParameter = 25;
|
|
|
-}; // namespace CompletionItemKind
|
|
|
+struct SymbolInformation {
|
|
|
+ /**
|
|
|
+ * The name of this symbol.
|
|
|
+ */
|
|
|
+ String name;
|
|
|
|
|
|
-/**
|
|
|
- * Defines whether the insert text in a completion item should be interpreted as
|
|
|
- * plain text or a snippet.
|
|
|
- */
|
|
|
-namespace InsertTextFormat {
|
|
|
-/**
|
|
|
- * The primary text to be inserted is treated as a plain string.
|
|
|
+ /**
|
|
|
+ * The kind of this symbol.
|
|
|
*/
|
|
|
-static const int PlainText = 1;
|
|
|
+ int kind = SymbolKind::File;
|
|
|
|
|
|
-/**
|
|
|
- * The primary text to be inserted is treated as a snippet.
|
|
|
- *
|
|
|
- * A snippet can define tab stops and placeholders with `$1`, `$2`
|
|
|
- * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
|
|
|
- * the end of the snippet. Placeholders with equal identifiers are linked,
|
|
|
- * that is typing in one will update others too.
|
|
|
+ /**
|
|
|
+ * Indicates if this symbol is deprecated.
|
|
|
*/
|
|
|
-static const int Snippet = 2;
|
|
|
-}; // namespace InsertTextFormat
|
|
|
+ bool deprecated = false;
|
|
|
|
|
|
-struct CompletionItem {
|
|
|
/**
|
|
|
- * The label of this completion item. By default
|
|
|
- * also the text that is inserted when selecting
|
|
|
- * this completion.
|
|
|
+ * The location of this symbol. The location's range is used by a tool
|
|
|
+ * to reveal the location in the editor. If the symbol is selected in the
|
|
|
+ * tool the range's start information is used to position the cursor. So
|
|
|
+ * the range usually spans more then the actual symbol's name and does
|
|
|
+ * normally include things like visibility modifiers.
|
|
|
+ *
|
|
|
+ * The range doesn't have to denote a node range in the sense of a abstract
|
|
|
+ * syntax tree. It can therefore not be used to re-construct a hierarchy of
|
|
|
+ * the symbols.
|
|
|
*/
|
|
|
- String label;
|
|
|
+ Location location;
|
|
|
|
|
|
/**
|
|
|
- * The kind of this completion item. Based of the kind
|
|
|
- * an icon is chosen by the editor. The standardized set
|
|
|
- * of available values is defined in `CompletionItemKind`.
|
|
|
+ * The name of the symbol containing this symbol. This information is for
|
|
|
+ * user interface purposes (e.g. to render a qualifier in the user interface
|
|
|
+ * if necessary). It can't be used to re-infer a hierarchy for the document
|
|
|
+ * symbols.
|
|
|
*/
|
|
|
- int kind;
|
|
|
+ String containerName;
|
|
|
+
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
+ Dictionary dict;
|
|
|
+ dict["name"] = name;
|
|
|
+ dict["kind"] = kind;
|
|
|
+ dict["deprecated"] = deprecated;
|
|
|
+ dict["location"] = location.to_json();
|
|
|
+ dict["containerName"] = containerName;
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
+struct DocumentedSymbolInformation : public SymbolInformation {
|
|
|
/**
|
|
|
* A human-readable string with additional information
|
|
|
- * about this item, like type or symbol information.
|
|
|
*/
|
|
|
String detail;
|
|
|
|
|
|
/**
|
|
|
* A human-readable string that represents a doc-comment.
|
|
|
*/
|
|
|
- MarkupContent documentation;
|
|
|
-
|
|
|
- /**
|
|
|
- * Indicates if this item is deprecated.
|
|
|
- */
|
|
|
- bool deprecated = false;
|
|
|
+ String documentation;
|
|
|
+};
|
|
|
|
|
|
- /**
|
|
|
- * Select this item when showing.
|
|
|
- *
|
|
|
- * *Note* that only one completion item can be selected and that the
|
|
|
- * tool / client decides which item that is. The rule is that the *first*
|
|
|
- * item of those that match best is selected.
|
|
|
- */
|
|
|
- bool preselect = false;
|
|
|
+/**
|
|
|
+ * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
|
|
|
+ * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
|
|
|
+ * e.g. the range of an identifier.
|
|
|
+ */
|
|
|
+struct DocumentSymbol {
|
|
|
|
|
|
/**
|
|
|
- * A string that should be used when comparing this item
|
|
|
- * with other items. When `falsy` the label is used.
|
|
|
+ * The name of this symbol. Will be displayed in the user interface and therefore must not be
|
|
|
+ * an empty string or a string only consisting of white spaces.
|
|
|
*/
|
|
|
- String sortText;
|
|
|
+ String name;
|
|
|
|
|
|
/**
|
|
|
- * A string that should be used when filtering a set of
|
|
|
- * completion items. When `falsy` the label is used.
|
|
|
+ * More detail for this symbol, e.g the signature of a function.
|
|
|
*/
|
|
|
- String filterText;
|
|
|
+ String detail;
|
|
|
|
|
|
/**
|
|
|
- * A string that should be inserted into a document when selecting
|
|
|
- * this completion. When `falsy` the label is used.
|
|
|
- *
|
|
|
- * The `insertText` is subject to interpretation by the client side.
|
|
|
- * Some tools might not take the string literally. For example
|
|
|
- * VS Code when code complete is requested in this example `con<cursor position>`
|
|
|
- * and a completion item with an `insertText` of `console` is provided it
|
|
|
- * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
|
|
|
- * since it avoids additional client side interpretation.
|
|
|
- *
|
|
|
- * @deprecated Use textEdit instead.
|
|
|
+ * Documentation for this symbol
|
|
|
*/
|
|
|
- String insertText;
|
|
|
+ String documentation;
|
|
|
|
|
|
/**
|
|
|
- * The format of the insert text. The format applies to both the `insertText` property
|
|
|
- * and the `newText` property of a provided `textEdit`.
|
|
|
+ * The kind of this symbol.
|
|
|
*/
|
|
|
- int insertTextFormat;
|
|
|
+ int kind = SymbolKind::File;
|
|
|
|
|
|
/**
|
|
|
- * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
|
|
|
- * `insertText` is ignored.
|
|
|
- *
|
|
|
- * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
|
|
|
- * has been requested.
|
|
|
+ * Indicates if this symbol is deprecated.
|
|
|
*/
|
|
|
- TextEdit textEdit;
|
|
|
+ bool deprecated = false;
|
|
|
|
|
|
/**
|
|
|
- * An optional array of additional text edits that are applied when
|
|
|
- * selecting this completion. Edits must not overlap (including the same insert position)
|
|
|
- * with the main edit nor with themselves.
|
|
|
- *
|
|
|
- * Additional text edits should be used to change text unrelated to the current cursor position
|
|
|
- * (for example adding an import statement at the top of the file if the completion item will
|
|
|
- * insert an unqualified type).
|
|
|
+ * The range enclosing this symbol not including leading/trailing whitespace but everything else
|
|
|
+ * like comments. This information is typically used to determine if the clients cursor is
|
|
|
+ * inside the symbol to reveal in the symbol in the UI.
|
|
|
*/
|
|
|
- Vector<TextEdit> additionalTextEdits;
|
|
|
+ Range range;
|
|
|
|
|
|
/**
|
|
|
- * An optional set of characters that when pressed while this completion is active will accept it first and
|
|
|
- * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
|
|
|
- * characters will be ignored.
|
|
|
+ * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
|
|
|
+ * Must be contained by the `range`.
|
|
|
*/
|
|
|
- Vector<String> commitCharacters;
|
|
|
+ Range selectionRange;
|
|
|
|
|
|
- /**
|
|
|
- * An optional command that is executed *after* inserting this completion. *Note* that
|
|
|
- * additional modifications to the current document should be described with the
|
|
|
- * additionalTextEdits-property.
|
|
|
- */
|
|
|
- Command command;
|
|
|
+ DocumentUri uri;
|
|
|
+ String script_path;
|
|
|
|
|
|
/**
|
|
|
- * A data entry field that is preserved on a completion item between
|
|
|
- * a completion and a completion resolve request.
|
|
|
+ * Children of this symbol, e.g. properties of a class.
|
|
|
*/
|
|
|
- Variant data;
|
|
|
+ Vector<DocumentSymbol> children;
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
- dict["label"] = label;
|
|
|
- dict["kind"] = kind;
|
|
|
+ dict["name"] = name;
|
|
|
dict["detail"] = detail;
|
|
|
- dict["documentation"] = documentation.to_json();
|
|
|
+ dict["kind"] = kind;
|
|
|
dict["deprecated"] = deprecated;
|
|
|
- dict["preselect"] = preselect;
|
|
|
- dict["sortText"] = sortText;
|
|
|
- dict["filterText"] = filterText;
|
|
|
- dict["insertText"] = insertText;
|
|
|
- if (commitCharacters.size()) dict["commitCharacters"] = commitCharacters;
|
|
|
- dict["command"] = command.to_json();
|
|
|
- dict["data"] = data;
|
|
|
+ dict["range"] = range.to_json();
|
|
|
+ dict["selectionRange"] = selectionRange.to_json();
|
|
|
+ Array arr;
|
|
|
+ arr.resize(children.size());
|
|
|
+ for (int i = 0; i < children.size(); i++) {
|
|
|
+ arr[i] = children[i].to_json();
|
|
|
+ }
|
|
|
+ dict["children"] = arr;
|
|
|
return dict;
|
|
|
}
|
|
|
|
|
|
- void load(const Dictionary &p_dict) {
|
|
|
- if (p_dict.has("label")) label = p_dict["label"];
|
|
|
- if (p_dict.has("kind")) kind = p_dict["kind"];
|
|
|
- if (p_dict.has("detail")) detail = p_dict["detail"];
|
|
|
- if (p_dict.has("documentation")) {
|
|
|
- Variant doc = p_dict["documentation"];
|
|
|
- if (doc.get_type() == Variant::STRING) {
|
|
|
- documentation.value = doc;
|
|
|
- } else if (doc.get_type() == Variant::DICTIONARY) {
|
|
|
- Dictionary v = doc;
|
|
|
- documentation.value = v["value"];
|
|
|
- }
|
|
|
+ void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
|
|
|
+ DocumentedSymbolInformation si;
|
|
|
+ if (p_join_name && !p_container.empty()) {
|
|
|
+ si.name = p_container + ">" + name;
|
|
|
+ } else {
|
|
|
+ si.name = name;
|
|
|
+ }
|
|
|
+ si.kind = kind;
|
|
|
+ si.containerName = p_container;
|
|
|
+ si.deprecated = deprecated;
|
|
|
+ si.location.uri = p_uri;
|
|
|
+ si.location.range = range;
|
|
|
+ si.detail = detail;
|
|
|
+ si.documentation = documentation;
|
|
|
+ r_list.push_back(si);
|
|
|
+ for (int i = 0; i < children.size(); i++) {
|
|
|
+ children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
|
|
|
}
|
|
|
- if (p_dict.has("deprecated")) deprecated = p_dict["deprecated"];
|
|
|
- if (p_dict.has("preselect")) preselect = p_dict["preselect"];
|
|
|
- if (p_dict.has("sortText")) sortText = p_dict["sortText"];
|
|
|
- if (p_dict.has("filterText")) filterText = p_dict["filterText"];
|
|
|
- if (p_dict.has("insertText")) insertText = p_dict["insertText"];
|
|
|
- if (p_dict.has("data")) data = p_dict["data"];
|
|
|
}
|
|
|
-};
|
|
|
|
|
|
-/**
|
|
|
- * Represents a collection of [completion items](#CompletionItem) to be presented
|
|
|
- * in the editor.
|
|
|
- */
|
|
|
-struct CompletionList {
|
|
|
- /**
|
|
|
- * This list it not complete. Further typing should result in recomputing
|
|
|
- * this list.
|
|
|
- */
|
|
|
- bool isIncomplete;
|
|
|
+ _FORCE_INLINE_ MarkupContent render() const {
|
|
|
+ MarkupContent markdown;
|
|
|
+ if (detail.length()) {
|
|
|
+ markdown.value = "\t" + detail + "\n\n";
|
|
|
+ }
|
|
|
+ if (documentation.length()) {
|
|
|
+ markdown.value += documentation + "\n\n";
|
|
|
+ }
|
|
|
+ if (script_path.length()) {
|
|
|
+ markdown.value += "Defined in [" + script_path + "](" + uri + ")";
|
|
|
+ }
|
|
|
+ return markdown;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * The completion items.
|
|
|
- */
|
|
|
- Vector<CompletionItem> items;
|
|
|
+ _FORCE_INLINE_ CompletionItem make_completion_item(bool with_doc = false) const {
|
|
|
+
|
|
|
+ lsp::CompletionItem item;
|
|
|
+ item.label = name;
|
|
|
+
|
|
|
+ if (with_doc) {
|
|
|
+ item.documentation = render();
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (kind) {
|
|
|
+ case lsp::SymbolKind::Enum:
|
|
|
+ item.kind = lsp::CompletionItemKind::Enum;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Class:
|
|
|
+ item.kind = lsp::CompletionItemKind::Class;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Property:
|
|
|
+ item.kind = lsp::CompletionItemKind::Property;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Method:
|
|
|
+ case lsp::SymbolKind::Function:
|
|
|
+ item.kind = lsp::CompletionItemKind::Method;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Event:
|
|
|
+ item.kind = lsp::CompletionItemKind::Event;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Constant:
|
|
|
+ item.kind = lsp::CompletionItemKind::Constant;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::Variable:
|
|
|
+ item.kind = lsp::CompletionItemKind::Variable;
|
|
|
+ break;
|
|
|
+ case lsp::SymbolKind::File:
|
|
|
+ item.kind = lsp::CompletionItemKind::File;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ item.kind = lsp::CompletionItemKind::Text;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return item;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -1194,7 +1239,7 @@ struct FoldingRange {
|
|
|
*/
|
|
|
String kind = FoldingRangeKind::Region;
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["startLine"] = startLine;
|
|
|
dict["startCharacter"] = startCharacter;
|
|
@@ -1276,7 +1321,7 @@ struct Hover {
|
|
|
*/
|
|
|
Range range;
|
|
|
|
|
|
- Dictionary to_json() const {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() const {
|
|
|
Dictionary dict;
|
|
|
dict["range"] = range.to_json();
|
|
|
dict["contents"] = contents.to_json();
|
|
@@ -1410,7 +1455,7 @@ struct ServerCapabilities {
|
|
|
*/
|
|
|
ExecuteCommandOptions executeCommandProvider;
|
|
|
|
|
|
- Dictionary to_json() {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() {
|
|
|
Dictionary dict;
|
|
|
dict["textDocumentSync"] = (int)textDocumentSync.change;
|
|
|
dict["completionProvider"] = completionProvider.to_json();
|
|
@@ -1444,7 +1489,7 @@ struct InitializeResult {
|
|
|
*/
|
|
|
ServerCapabilities capabilities;
|
|
|
|
|
|
- Dictionary to_json() {
|
|
|
+ _FORCE_INLINE_ Dictionary to_json() {
|
|
|
Dictionary dict;
|
|
|
dict["capabilities"] = capabilities.to_json();
|
|
|
return dict;
|