| 1 |
#pragma once |
| 2 |
#include "lsTextEdit.h" |
| 3 |
#include "lsMarkedString.h" |
| 4 |
#include "lsCommand.h" |
| 5 |
|
| 6 |
// The kind of a completion entry. |
| 7 |
enum class lsCompletionItemKind |
| 8 |
{ |
| 9 |
Text = 1, |
| 10 |
Method = 2, |
| 11 |
Function = 3, |
| 12 |
Constructor = 4, |
| 13 |
Field = 5, |
| 14 |
Variable = 6, |
| 15 |
Class = 7, |
| 16 |
Interface = 8, |
| 17 |
Module = 9, |
| 18 |
Property = 10, |
| 19 |
Unit = 11, |
| 20 |
Value = 12, |
| 21 |
Enum = 13, |
| 22 |
Keyword = 14, |
| 23 |
Snippet = 15, |
| 24 |
Color = 16, |
| 25 |
File = 17, |
| 26 |
Reference = 18, |
| 27 |
Folder = 19, |
| 28 |
EnumMember = 20, |
| 29 |
Constant = 21, |
| 30 |
Struct = 22, |
| 31 |
Event = 23, |
| 32 |
Operator = 24, |
| 33 |
TypeParameter = 25, |
| 34 |
}; |
| 35 |
MAKE_REFLECT_TYPE_PROXY(lsCompletionItemKind); |
| 36 |
|
| 37 |
// Defines whether the insert text in a completion item should be interpreted as |
| 38 |
// plain text or a snippet. |
| 39 |
enum class lsInsertTextFormat |
| 40 |
{ |
| 41 |
// The primary text to be inserted is treated as a plain string. |
| 42 |
PlainText = 1, |
| 43 |
|
| 44 |
// The primary text to be inserted is treated as a snippet. |
| 45 |
// |
| 46 |
// A snippet can define tab stops and placeholders with `$1`, `$2` |
| 47 |
// and `${3:foo}`. `$0` defines the final tab stop, it defaults to |
| 48 |
// the end of the snippet. Placeholders with equal identifiers are linked, |
| 49 |
// that is typing in one will update others too. |
| 50 |
// |
| 51 |
// See also: |
| 52 |
// https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md |
| 53 |
Snippet = 2 |
| 54 |
}; |
| 55 |
MAKE_REFLECT_TYPE_PROXY(lsInsertTextFormat); |
| 56 |
|
| 57 |
namespace lsp |
| 58 |
{ |
| 59 |
std::string ToString(lsCompletionItemKind); |
| 60 |
std::string ToString(lsInsertTextFormat); |
| 61 |
} // namespace lsp |
| 62 |
/** |
| 63 |
* The Completion request is sent from the client to the server to compute completion items at a given cursor position. |
| 64 |
* Completion items are presented in the IntelliSense user class. If computing complete completion items is expensive |
| 65 |
* servers can additional provide a handler for the resolve completion item request. This request is send when a |
| 66 |
* completion item is selected in the user class. |
| 67 |
*/ |
| 68 |
struct lsCompletionItem |
| 69 |
{ |
| 70 |
|
| 71 |
// The label of this completion item. By default |
| 72 |
// also the text that is inserted when selecting |
| 73 |
// this completion. |
| 74 |
std::string label; |
| 75 |
|
| 76 |
// The kind of this completion item. Based of the kind |
| 77 |
// an icon is chosen by the editor. |
| 78 |
optional<lsCompletionItemKind> kind; |
| 79 |
|
| 80 |
// A human-readable string with additional information |
| 81 |
// about this item, like type or symbol information. |
| 82 |
optional<std::string> detail; |
| 83 |
|
| 84 |
// A human-readable string that represents a doc-comment. |
| 85 |
optional<std::pair<optional<std::string>, optional<MarkupContent>>> documentation; |
| 86 |
|
| 87 |
/** |
| 88 |
* Indicates if this item is deprecated. |
| 89 |
*/ |
| 90 |
optional<bool> deprecated; |
| 91 |
|
| 92 |
/** |
| 93 |
* Select this item when showing. |
| 94 |
* |
| 95 |
* *Note* that only one completion item can be selected and that the |
| 96 |
* tool / client decides which item that is. The rule is that the *first |
| 97 |
* item of those that match best is selected. |
| 98 |
*/ |
| 99 |
optional<bool> preselect; |
| 100 |
|
| 101 |
// Internal information to order candidates. |
| 102 |
int relevance = 0; |
| 103 |
|
| 104 |
// A string that shoud be used when comparing this item |
| 105 |
// with other items. When `falsy` the label is used. |
| 106 |
optional<std::string> sortText; |
| 107 |
|
| 108 |
// A string that should be used when filtering a set of |
| 109 |
// completion items. When `falsy` the label is used. |
| 110 |
optional<std::string> filterText; |
| 111 |
|
| 112 |
// A string that should be inserted a document when selecting |
| 113 |
// this completion. When `falsy` the label is used. |
| 114 |
optional<std::string> insertText; |
| 115 |
|
| 116 |
// The format of the insert text. The format applies to both the `insertText` |
| 117 |
// property and the `newText` property of a provided `textEdit`. |
| 118 |
optional<lsInsertTextFormat> insertTextFormat; |
| 119 |
|
| 120 |
// An edit which is applied to a document when selecting this completion. When |
| 121 |
// an edit is provided the value of `insertText` is ignored. |
| 122 |
// |
| 123 |
// *Note:* The range of the edit must be a single line range and it must |
| 124 |
// contain the position at which completion has been requested. |
| 125 |
optional<lsTextEdit> textEdit; |
| 126 |
|
| 127 |
// An optional array of additional text edits that are applied when |
| 128 |
// selecting this completion. Edits must not overlap with the main edit |
| 129 |
// nor with themselves. |
| 130 |
// std::vector<TextEdit> additionalTextEdits; |
| 131 |
|
| 132 |
// An optional command that is executed *after* inserting this completion. |
| 133 |
// *Note* that additional modifications to the current document should be |
| 134 |
// described with the additionalTextEdits-property. Command command; |
| 135 |
|
| 136 |
// An data entry field that is preserved on a completion item between |
| 137 |
// a completion and a completion resolve request. |
| 138 |
// data ? : any |
| 139 |
|
| 140 |
// Use this helper to figure out what content the completion item will insert |
| 141 |
// into the document, as it could live in either |textEdit|, |insertText|, or |
| 142 |
// |label|. |
| 143 |
std::string const& InsertedContent() const; |
| 144 |
|
| 145 |
std::string DisplayText(); |
| 146 |
/** |
| 147 |
* An optional array of additional text edits that are applied when |
| 148 |
* selecting this completion. Edits must not overlap (including the same insert position) |
| 149 |
* with the main edit nor with themselves. |
| 150 |
* |
| 151 |
* Additional text edits should be used to change text unrelated to the current cursor position |
| 152 |
* (for example adding an import statement at the top of the file if the completion item will |
| 153 |
* insert an unqualified type). |
| 154 |
*/ |
| 155 |
optional<std::vector<lsTextEdit>> additionalTextEdits; |
| 156 |
|
| 157 |
/** |
| 158 |
* An optional set of characters that when pressed while this completion is active will accept it first and |
| 159 |
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous |
| 160 |
* characters will be ignored. |
| 161 |
*/ |
| 162 |
optional<std::vector<std::string>> commitCharacters; |
| 163 |
|
| 164 |
/** |
| 165 |
* An optional command that is executed *after* inserting this completion. *Note* that |
| 166 |
* additional modifications to the current document should be described with the |
| 167 |
* additionalTextEdits-property. |
| 168 |
*/ |
| 169 |
optional<lsCommandWithAny> command; |
| 170 |
|
| 171 |
/** |
| 172 |
* An data entry field that is preserved on a completion item between a completion and a completion resolve request. |
| 173 |
*/ |
| 174 |
optional<lsp::Any> data; |
| 175 |
std::string ToString(); |
| 176 |
MAKE_SWAP_METHOD( |
| 177 |
lsCompletionItem, label, kind, detail, documentation, sortText, insertText, filterText, insertTextFormat, |
| 178 |
textEdit, deprecated, preselect, additionalTextEdits, commitCharacters, command, data |
| 179 |
); |
| 180 |
}; |
| 181 |
|
| 182 |
MAKE_REFLECT_STRUCT( |
| 183 |
lsCompletionItem, label, kind, detail, documentation, sortText, insertText, filterText, insertTextFormat, textEdit, |
| 184 |
deprecated, preselect, additionalTextEdits, commitCharacters, command, data |
| 185 |
); |
| 186 |
|
| 187 |
struct CompletionList |
| 188 |
{ |
| 189 |
// This list it not complete. Further typing should result in recomputing |
| 190 |
// this list. |
| 191 |
bool isIncomplete = false; |
| 192 |
// The completion items. |
| 193 |
std::vector<lsCompletionItem> items; |
| 194 |
|
| 195 |
void swap(CompletionList& arg) noexcept |
| 196 |
{ |
| 197 |
items.swap(arg.items); |
| 198 |
std::swap(isIncomplete, arg.isIncomplete); |
| 199 |
} |
| 200 |
}; |
| 201 |
MAKE_REFLECT_STRUCT(CompletionList, isIncomplete, items); |