@@ -101,8 +101,7 @@ final class SwiftCompletionTests: XCTestCase {
101
101
XCTAssertEqual ( abc. kind, . property)
102
102
XCTAssertEqual ( abc. detail, " Int " )
103
103
XCTAssertEqual ( abc. filterText, " abc " )
104
- // FIXME:
105
- XCTAssertNil ( abc. textEdit)
104
+ XCTAssertEqual ( abc. textEdit, TextEdit ( range: Position ( line: 4 , utf16index: 9 ) ..< Position ( line: 4 , utf16index: 9 ) , newText: " abc " ) )
106
105
XCTAssertEqual ( abc. insertText, " abc " )
107
106
XCTAssertEqual ( abc. insertTextFormat, . plain)
108
107
}
@@ -111,8 +110,18 @@ final class SwiftCompletionTests: XCTestCase {
111
110
let inIdent = try ! sk. sendSync ( CompletionRequest (
112
111
textDocument: TextDocumentIdentifier ( url) ,
113
112
position: Position ( line: 4 , utf16index: col) ) )
113
+ guard let abc = inIdent. items. first ( where: { $0. label == " abc " } ) else {
114
+ XCTFail ( " No completion item with label 'abc' " )
115
+ return
116
+ }
117
+
114
118
// If we switch to server-side filtering this will change.
115
- XCTAssertEqual ( inIdent, selfDot)
119
+ XCTAssertEqual ( abc. kind, . property)
120
+ XCTAssertEqual ( abc. detail, " Int " )
121
+ XCTAssertEqual ( abc. filterText, " abc " )
122
+ XCTAssertEqual ( abc. textEdit, TextEdit ( range: Position ( line: 4 , utf16index: 9 ) ..< Position ( line: 4 , utf16index: col) , newText: " abc " ) )
123
+ XCTAssertEqual ( abc. insertText, " abc " )
124
+ XCTAssertEqual ( abc. insertTextFormat, . plain)
116
125
}
117
126
118
127
let after = try ! sk. sendSync ( CompletionRequest (
@@ -150,8 +159,7 @@ final class SwiftCompletionTests: XCTestCase {
150
159
XCTAssertEqual ( test. kind, . method)
151
160
XCTAssertEqual ( test. detail, " Void " )
152
161
XCTAssertEqual ( test. filterText, " test(a:) " )
153
- // FIXME:
154
- XCTAssertNil ( test. textEdit)
162
+ XCTAssertEqual ( test. textEdit, TextEdit ( range: Position ( line: 4 , utf16index: 9 ) ..< Position ( line: 4 , utf16index: 9 ) , newText: " test(a: ${1:Int}) " ) )
155
163
XCTAssertEqual ( test. insertText, " test(a: ${1:Int}) " )
156
164
XCTAssertEqual ( test. insertTextFormat, . snippet)
157
165
}
@@ -162,8 +170,7 @@ final class SwiftCompletionTests: XCTestCase {
162
170
XCTAssertEqual ( test. kind, . method)
163
171
XCTAssertEqual ( test. detail, " Void " )
164
172
XCTAssertEqual ( test. filterText, " test(:) " )
165
- // FIXME:
166
- XCTAssertNil ( test. textEdit)
173
+ XCTAssertEqual ( test. textEdit, TextEdit ( range: Position ( line: 8 , utf16index: 9 ) ..< Position ( line: 8 , utf16index: 9 ) , newText: " test(${1:b: Int}) " ) )
167
174
XCTAssertEqual ( test. insertText, " test(${1:b: Int}) " )
168
175
XCTAssertEqual ( test. insertTextFormat, . snippet)
169
176
}
@@ -179,8 +186,7 @@ final class SwiftCompletionTests: XCTestCase {
179
186
XCTAssertEqual ( test. kind, . method)
180
187
XCTAssertEqual ( test. detail, " Void " )
181
188
XCTAssertEqual ( test. filterText, " test(a:) " )
182
- // FIXME:
183
- XCTAssertNil ( test. textEdit)
189
+ XCTAssertEqual ( test. textEdit, TextEdit ( range: Position ( line: 4 , utf16index: 9 ) ..< Position ( line: 4 , utf16index: 9 ) , newText: " test(a: ) " ) )
184
190
XCTAssertEqual ( test. insertText, " test(a: ) " )
185
191
XCTAssertEqual ( test. insertTextFormat, . plain)
186
192
}
@@ -192,7 +198,7 @@ final class SwiftCompletionTests: XCTestCase {
192
198
XCTAssertEqual ( test. detail, " Void " )
193
199
XCTAssertEqual ( test. filterText, " test(:) " )
194
200
// FIXME:
195
- XCTAssertNil ( test. textEdit)
201
+ XCTAssertEqual ( test. textEdit, TextEdit ( range : Position ( line : 8 , utf16index : 9 ) ..< Position ( line : 8 , utf16index : 9 ) , newText : " test() " ) )
196
202
XCTAssertEqual ( test. insertText, " test() " )
197
203
XCTAssertEqual ( test. insertTextFormat, . plain)
198
204
}
@@ -221,4 +227,30 @@ final class SwiftCompletionTests: XCTestCase {
221
227
position: Position ( line: 1 , utf16index: 0 ) ) )
222
228
XCTAssertTrue ( outOfRange2. isIncomplete)
223
229
}
230
+
231
+ func testCompletionOptional( ) {
232
+ initializeServer ( )
233
+ let url = URL ( fileURLWithPath: " /a.swift " )
234
+ let text = """
235
+ struct Foo {
236
+ let bar: Int
237
+ }
238
+ let a: Foo? = Foo(bar: 1)
239
+ a.ba
240
+ """
241
+ openDocument ( text: text, url: url)
242
+
243
+ for col in 2 ... 4 {
244
+ let response = try ! sk. sendSync ( CompletionRequest (
245
+ textDocument: TextDocumentIdentifier ( url) ,
246
+ position: Position ( line: 4 , utf16index: col) ) )
247
+ XCTAssertFalse ( response. isIncomplete)
248
+ guard let item = response. items. first ( where: { $0. label == " bar " } ) else {
249
+ XCTFail ( " No completion item with label 'bar' " )
250
+ return
251
+ }
252
+ XCTAssertEqual ( item. filterText, " .bar " )
253
+ XCTAssertEqual ( item. textEdit, TextEdit ( range: Position ( line: 4 , utf16index: 1 ) ..< Position ( line: 4 , utf16index: col) , newText: " ?.bar " ) )
254
+ }
255
+ }
224
256
}
0 commit comments