1 #pragma once 2 #include "lsp.h" 3 4 // The kind of a completion entry. 5 enum class lsCompletionItemKind { 6 Text = 1, 7 Method = 2, 8 Function = 3, 9 Constructor = 4, 10 Field = 5, 11 Variable = 6, 12 Class = 7, 13 Interface = 8, 14 Module = 9, 15 Property = 10, 16 Unit = 11, 17 Value = 12, 18 Enum = 13, 19 Keyword = 14, 20 Snippet = 15, 21 Color = 16, 22 File = 17, 23 Reference = 18, 24 Folder = 19, 25 EnumMember = 20, 26 Constant = 21, 27 Struct = 22, 28 Event = 23, 29 Operator = 24, 30 TypeParameter = 25, 31 }; 32 MAKE_REFLECT_TYPE_PROXY(lsCompletionItemKind); 33 34 // Defines whether the insert text in a completion item should be interpreted as 35 // plain text or a snippet. 36 enum class lsInsertTextFormat { 37 // The primary text to be inserted is treated as a plain string. 38 PlainText = 1, 39 40 // The primary text to be inserted is treated as a snippet. 41 // 42 // A snippet can define tab stops and placeholders with `$1`, `$2` 43 // and `${3:foo}`. `$0` defines the final tab stop, it defaults to 44 // the end of the snippet. Placeholders with equal identifiers are linked, 45 // that is typing in one will update others too. 46 // 47 // See also: 48 // https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md 49 Snippet = 2 50 }; 51 MAKE_REFLECT_TYPE_PROXY(lsInsertTextFormat); 52 53 struct lsCompletionItem { 54 // A set of function parameters. Used internally for signature help. Not sent 55 // to vscode. 56 std::vector<std::string> parameters_; 57 58 // The label of this completion item. By default 59 // also the text that is inserted when selecting 60 // this completion. 61 std::string label; 62 63 // The kind of this completion item. Based of the kind 64 // an icon is chosen by the editor. 65 lsCompletionItemKind kind = lsCompletionItemKind::Text; 66 67 // A human-readable string with additional information 68 // about this item, like type or symbol information. 69 std::string detail; 70 71 // A human-readable string that represents a doc-comment. 72 optional<std::string> documentation; 73 74 // Internal information to order candidates. 75 int score_; 76 unsigned priority_; 77 78 // Use <> or "" by default as include path. 79 bool use_angle_brackets_ = false; 80 81 // A string that shoud be used when comparing this item 82 // with other items. When `falsy` the label is used. 83 std::string sortText; 84 85 // A string that should be used when filtering a set of 86 // completion items. When `falsy` the label is used. 87 optional<std::string> filterText; 88 89 // A string that should be inserted a document when selecting 90 // this completion. When `falsy` the label is used. 91 std::string insertText; 92 93 // The format of the insert text. The format applies to both the `insertText` 94 // property and the `newText` property of a provided `textEdit`. 95 lsInsertTextFormat insertTextFormat = lsInsertTextFormat::PlainText; 96 97 // An edit which is applied to a document when selecting this completion. When 98 // an edit is provided the value of `insertText` is ignored. 99 // 100 // *Note:* The range of the edit must be a single line range and it must 101 // contain the position at which completion has been requested. 102 optional<lsTextEdit> textEdit; 103 104 // An optional array of additional text edits that are applied when 105 // selecting this completion. Edits must not overlap with the main edit 106 // nor with themselves. 107 // std::vector<TextEdit> additionalTextEdits; 108 109 // An optional command that is executed *after* inserting this completion. 110 // *Note* that additional modifications to the current document should be 111 // described with the additionalTextEdits-property. Command command; 112 113 // An data entry field that is preserved on a completion item between 114 // a completion and a completion resolve request. 115 // data ? : any 116 117 // Use this helper to figure out what content the completion item will insert 118 // into the document, as it could live in either |textEdit|, |insertText|, or 119 // |label|. InsertedContentlsCompletionItem120 const std::string& InsertedContent() const { 121 if (textEdit) 122 return textEdit->newText; 123 if (!insertText.empty()) 124 return insertText; 125 return label; 126 } 127 }; 128 MAKE_REFLECT_STRUCT(lsCompletionItem, 129 label, 130 kind, 131 detail, 132 documentation, 133 sortText, 134 insertText, 135 filterText, 136 insertTextFormat, 137 textEdit); 138