Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit 1a743f4

Browse files
committed
Implement CompletionItem.insertTextFormat
1 parent f4eaab0 commit 1a743f4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Sources/LanguageServerProtocol/Types/CompletionItem.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ import Foundation
1212
import Ogra
1313
import Runes
1414

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+
1528
///
1629
public struct CompletionItem {
1730

@@ -29,6 +42,9 @@ public struct CompletionItem {
2942
/// A human-readable string that represents a doc-comment.
3043
var documentation: String?
3144

45+
/// Indicates if this item is deprecated.
46+
var deprecated: Bool?
47+
3248
/// A string that shoud be used when comparing this item with other items. When `falsy` the
3349
/// label is used.
3450
var sortText: String?
@@ -39,8 +55,19 @@ public struct CompletionItem {
3955

4056
/// A string that should be inserted a document when selecting this completion. When `falsy` the
4157
/// 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.
4265
var insertText: String?
4366

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+
4471
/// An edit which is applied to a document when selecting this completion. When an edit is
4572
/// provided the value of insertText is ignored.
4673
var textEdit: TextEdit?
@@ -49,6 +76,11 @@ public struct CompletionItem {
4976
/// Edits must not overlap with the main edit nor with themselves.
5077
var additionalTextEdits: [TextEdit]?
5178

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+
5284
/// An optional command that is executed *after* inserting this completion.
5385
///
5486
/// - Note: That additional modifications to the current document should be described with the
@@ -92,6 +124,10 @@ extension CompletionItem : Ogra.Encodable {
92124
obj["insertText"] = JSON.string(insertText)
93125
}
94126

127+
if let insertTextFormat = self.insertTextFormat {
128+
obj["insertTextFormat"] = JSON.number(NSNumber(value: insertTextFormat.rawValue))
129+
}
130+
95131
if let textEdit = self.textEdit {
96132
obj["textEdit"] = textEdit.encode()
97133
}

0 commit comments

Comments
 (0)