@@ -31,6 +31,7 @@ final class SwiftCompletionTests: XCTestCase {
31
31
32
32
func testCompletionBasic( ) async throws {
33
33
try await SkipUnless . sourcekitdSupportsPlugin ( )
34
+ try await SkipUnless . sourcekitdSupportsFullDocumentationInCompletion ( )
34
35
35
36
let testClient = try await TestSourceKitLSPClient ( )
36
37
let uri = DocumentURI ( for: . swift)
@@ -39,6 +40,13 @@ final class SwiftCompletionTests: XCTestCase {
39
40
"""
40
41
struct S {
41
42
/// Documentation for `abc`.
43
+ ///
44
+ /// _More_ documentation for `abc`.
45
+ ///
46
+ /// Usage:
47
+ /// ```swift
48
+ /// S().abc
49
+ /// ```
42
50
var abc: Int
43
51
44
52
func test(a: Int) {
@@ -67,7 +75,19 @@ final class SwiftCompletionTests: XCTestCase {
67
75
if let abc = abc {
68
76
XCTAssertEqual ( abc. kind, . property)
69
77
XCTAssertEqual ( abc. detail, " Int " )
70
- XCTAssertEqual ( abc. documentation, . markupContent( MarkupContent ( kind: . markdown, value: " Documentation for abc. " ) ) )
78
+ assertMarkdown (
79
+ documentation: abc. documentation,
80
+ expected: """
81
+ Documentation for `abc`.
82
+
83
+ _More_ documentation for `abc`.
84
+
85
+ Usage:
86
+ ```swift
87
+ S().abc
88
+ ```
89
+ """
90
+ )
71
91
XCTAssertEqual ( abc. filterText, " abc " )
72
92
XCTAssertEqual ( abc. textEdit, . textEdit( TextEdit ( range: Range ( positions [ " 1️⃣ " ] ) , newText: " abc " ) ) )
73
93
XCTAssertEqual ( abc. insertText, " abc " )
@@ -87,7 +107,19 @@ final class SwiftCompletionTests: XCTestCase {
87
107
// If we switch to server-side filtering this will change.
88
108
XCTAssertEqual ( abc. kind, . property)
89
109
XCTAssertEqual ( abc. detail, " Int " )
90
- XCTAssertEqual ( abc. documentation, . markupContent( MarkupContent ( kind: . markdown, value: " Documentation for abc. " ) ) )
110
+ assertMarkdown (
111
+ documentation: abc. documentation,
112
+ expected: """
113
+ Documentation for `abc`.
114
+
115
+ _More_ documentation for `abc`.
116
+
117
+ Usage:
118
+ ```swift
119
+ S().abc
120
+ ```
121
+ """
122
+ )
91
123
XCTAssertEqual ( abc. filterText, " abc " )
92
124
XCTAssertEqual ( abc. textEdit, . textEdit( TextEdit ( range: positions [ " 1️⃣ " ] ..< offsetPosition, newText: " abc " ) ) )
93
125
XCTAssertEqual ( abc. insertText, " abc " )
@@ -1154,6 +1186,7 @@ final class SwiftCompletionTests: XCTestCase {
1154
1186
1155
1187
func testCompletionItemResolve( ) async throws {
1156
1188
try await SkipUnless . sourcekitdSupportsPlugin ( )
1189
+ try await SkipUnless . sourcekitdSupportsFullDocumentationInCompletion ( )
1157
1190
1158
1191
let capabilities = ClientCapabilities (
1159
1192
textDocument: TextDocumentClientCapabilities (
@@ -1187,9 +1220,37 @@ final class SwiftCompletionTests: XCTestCase {
1187
1220
let item = try XCTUnwrap ( completions. items. only)
1188
1221
XCTAssertNil ( item. documentation)
1189
1222
let resolvedItem = try await testClient. send ( CompletionItemResolveRequest ( item: item) )
1190
- XCTAssertEqual (
1191
- resolvedItem. documentation,
1192
- . markupContent( MarkupContent ( kind: . markdown, value: " Creates a true value " ) )
1223
+ assertMarkdown (
1224
+ documentation: resolvedItem. documentation,
1225
+ expected: " Creates a true value "
1226
+ )
1227
+ }
1228
+
1229
+ func testCompletionBriefDocumentationFallback( ) async throws {
1230
+ try await SkipUnless . sourcekitdSupportsPlugin ( )
1231
+ try await SkipUnless . sourcekitdSupportsFullDocumentationInCompletion ( )
1232
+
1233
+ let testClient = try await TestSourceKitLSPClient ( )
1234
+ let uri = DocumentURI ( for: . swift)
1235
+
1236
+ // We test completion for result builder build functions since they don't have full documentation
1237
+ // but still have brief documentation.
1238
+ let positions = testClient. openDocument (
1239
+ """
1240
+ @resultBuilder
1241
+ struct AnyBuilder {
1242
+ static func 1️⃣
1243
+ }
1244
+ """ ,
1245
+ uri: uri
1246
+ )
1247
+ let completions = try await testClient. send (
1248
+ CompletionRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
1249
+ )
1250
+ let item = try XCTUnwrap ( completions. items. filter { $0. label. contains ( " buildBlock " ) } . only)
1251
+ assertMarkdown (
1252
+ documentation: item. documentation,
1253
+ expected: " Required by every result builder to build combined results from statement blocks "
1193
1254
)
1194
1255
}
1195
1256
@@ -1253,6 +1314,20 @@ private func countFs(_ response: CompletionList) -> Int {
1253
1314
return response. items. filter { $0. label. hasPrefix ( " f " ) } . count
1254
1315
}
1255
1316
1317
+ private func assertMarkdown(
1318
+ documentation: StringOrMarkupContent ? ,
1319
+ expected: String ,
1320
+ file: StaticString = #filePath,
1321
+ line: UInt = #line
1322
+ ) {
1323
+ XCTAssertEqual (
1324
+ documentation,
1325
+ . markupContent( MarkupContent ( kind: . markdown, value: expected) ) ,
1326
+ file: file,
1327
+ line: line
1328
+ )
1329
+ }
1330
+
1256
1331
fileprivate extension Position {
1257
1332
func adding( columns: Int ) -> Position {
1258
1333
return Position ( line: line, utf16index: utf16index + columns)
0 commit comments