@@ -12,6 +12,19 @@ import Foundation
12
12
import Ogra
13
13
import Runes
14
14
15
+ /// Defines whether the insert text in a completion item should be interpreted as plain text or a snippet.
16
+ public enum InsertTextFormat : Int {
17
+ /// The primary text to be inserted is treated as a plain string.
18
+ case plainText = 1
19
+
20
+ /// The primary text to be inserted is treated as a snippet.
21
+ ///
22
+ /// A snippet can define tab stops and placeholders with `$1`, `$2` and `${3:foo}`. `$0` defines the final tab stop,
23
+ /// it defaults to the end of the snippet. Placeholders with equal identifiers are linked, that is typing in one
24
+ /// will update others too.
25
+ case snippet = 2
26
+ }
27
+
15
28
///
16
29
public struct CompletionItem {
17
30
@@ -29,6 +42,9 @@ public struct CompletionItem {
29
42
/// A human-readable string that represents a doc-comment.
30
43
var documentation : String ?
31
44
45
+ /// Indicates if this item is deprecated.
46
+ var deprecated : Bool ?
47
+
32
48
/// A string that shoud be used when comparing this item with other items. When `falsy` the
33
49
/// label is used.
34
50
var sortText : String ?
@@ -39,8 +55,19 @@ public struct CompletionItem {
39
55
40
56
/// A string that should be inserted a document when selecting this completion. When `falsy` the
41
57
/// label is used.
58
+ ///
59
+ /// The `insertText` is subject to interpretation by the client side. Some tools might not take the string
60
+ /// literally. For example VS Code when code complete is requested in this example `con<cursor position>` and a
61
+ /// completion item with an `insertText` of `console` is provided it will only insert `sole`. Therefore it is
62
+ /// recommended to use `textEdit` instead since it avoids additional client side interpretation.
63
+ ///
64
+ /// - Warning: This property is deprecated. Use `textEdit` instead.
42
65
var insertText : String ?
43
66
67
+ /// The format of the insert text. The format applies to both the `insertText` property and the `newText` property
68
+ /// of a provided `textEdit`.
69
+ var insertTextFormat : InsertTextFormat ? = . snippet
70
+
44
71
/// An edit which is applied to a document when selecting this completion. When an edit is
45
72
/// provided the value of insertText is ignored.
46
73
var textEdit : TextEdit ?
@@ -49,6 +76,11 @@ public struct CompletionItem {
49
76
/// Edits must not overlap with the main edit nor with themselves.
50
77
var additionalTextEdits : [ TextEdit ] ?
51
78
79
+ /// An optional set of characters that when pressed while this completion is active will accept it first and then
80
+ /// type that character. *Note* that all commit characters should have `length=1` and that superfluous characters
81
+ /// will be ignored.
82
+ var commitCharacters : [ Character ] ?
83
+
52
84
/// An optional command that is executed *after* inserting this completion.
53
85
///
54
86
/// - Note: That additional modifications to the current document should be described with the
@@ -92,6 +124,10 @@ extension CompletionItem : Ogra.Encodable {
92
124
obj [ " insertText " ] = JSON . string ( insertText)
93
125
}
94
126
127
+ if let insertTextFormat = self . insertTextFormat {
128
+ obj [ " insertTextFormat " ] = JSON . number ( NSNumber ( value: insertTextFormat. rawValue) )
129
+ }
130
+
95
131
if let textEdit = self . textEdit {
96
132
obj [ " textEdit " ] = textEdit. encode ( )
97
133
}
0 commit comments