@@ -31,6 +31,7 @@ final class SwiftCompletionTests: XCTestCase {
3131
3232 func testCompletionBasic( ) async throws {
3333 try await SkipUnless . sourcekitdSupportsPlugin ( )
34+ try await SkipUnless . sourcekitdSupportsFullDocumentationInCompletion ( )
3435
3536 let testClient = try await TestSourceKitLSPClient ( )
3637 let uri = DocumentURI ( for: . swift)
@@ -39,6 +40,13 @@ final class SwiftCompletionTests: XCTestCase {
3940 """
4041 struct S {
4142 /// Documentation for `abc`.
43+ ///
44+ /// _More_ documentation for `abc`.
45+ ///
46+ /// Usage:
47+ /// ```swift
48+ /// S().abc
49+ /// ```
4250 var abc: Int
4351
4452 func test(a: Int) {
@@ -67,7 +75,19 @@ final class SwiftCompletionTests: XCTestCase {
6775 if let abc = abc {
6876 XCTAssertEqual ( abc. kind, . property)
6977 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+ )
7191 XCTAssertEqual ( abc. filterText, " abc " )
7292 XCTAssertEqual ( abc. textEdit, . textEdit( TextEdit ( range: Range ( positions [ " 1️⃣ " ] ) , newText: " abc " ) ) )
7393 XCTAssertEqual ( abc. insertText, " abc " )
@@ -87,7 +107,19 @@ final class SwiftCompletionTests: XCTestCase {
87107 // If we switch to server-side filtering this will change.
88108 XCTAssertEqual ( abc. kind, . property)
89109 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+ )
91123 XCTAssertEqual ( abc. filterText, " abc " )
92124 XCTAssertEqual ( abc. textEdit, . textEdit( TextEdit ( range: positions [ " 1️⃣ " ] ..< offsetPosition, newText: " abc " ) ) )
93125 XCTAssertEqual ( abc. insertText, " abc " )
@@ -1154,6 +1186,7 @@ final class SwiftCompletionTests: XCTestCase {
11541186
11551187 func testCompletionItemResolve( ) async throws {
11561188 try await SkipUnless . sourcekitdSupportsPlugin ( )
1189+ try await SkipUnless . sourcekitdSupportsFullDocumentationInCompletion ( )
11571190
11581191 let capabilities = ClientCapabilities (
11591192 textDocument: TextDocumentClientCapabilities (
@@ -1187,9 +1220,37 @@ final class SwiftCompletionTests: XCTestCase {
11871220 let item = try XCTUnwrap ( completions. items. only)
11881221 XCTAssertNil ( item. documentation)
11891222 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 "
11931254 )
11941255 }
11951256
@@ -1253,6 +1314,20 @@ private func countFs(_ response: CompletionList) -> Int {
12531314 return response. items. filter { $0. label. hasPrefix ( " f " ) } . count
12541315}
12551316
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+
12561331fileprivate extension Position {
12571332 func adding( columns: Int ) -> Position {
12581333 return Position ( line: line, utf16index: utf16index + columns)
0 commit comments