@@ -203,7 +203,8 @@ final class SwiftSourceKitPluginTests: XCTestCase {
203
203
XCTAssertEqual ( result2. items. count, 1 )
204
204
XCTAssertEqual ( result2. items [ 0 ] . name, " " )
205
205
let doc = try await sourcekitd. completeDocumentation ( id: result2. items [ 0 ] . id)
206
- XCTAssertEqual ( doc. docFullAsXML, nil )
206
+ XCTAssertNil ( doc. docFullAsXML)
207
+ XCTAssertNil ( doc. docBrief)
207
208
}
208
209
209
210
func testMultipleFiles( ) async throws {
@@ -436,38 +437,47 @@ final class SwiftSourceKitPluginTests: XCTestCase {
436
437
let sym3 = try unwrap ( result. items. first ( where: { $0. name == " foo3() " } ) , " did not find foo3; got \( result. items) " )
437
438
438
439
let sym1Doc = try await sourcekitd. completeDocumentation ( id: sym1. id)
439
- XCTAssertEqual ( sym1Doc. docFullAsXML,
440
- """
441
- <Function file= " \( path) " line= " 3 " column= " 8 " > \
442
- <Name>foo1()</Name> \
443
- <USR>s:1a1PP4foo1yyF</USR> \
444
- <Declaration>func foo1()</Declaration> \
445
- <CommentParts> \
446
- <Abstract><Para>Protocol P foo1</Para></Abstract> \
447
- <Discussion><Note> \
448
- <Para>This documentation comment was inherited from <codeVoice>P</codeVoice>.</Para> \
449
- </Note></Discussion> \
450
- </CommentParts> \
451
- </Function>
452
- """ )
440
+ assertDocumentation (
441
+ full: sourcekitd. supportsFullDocumentationInCompletion,
442
+ documentation: sym1Doc,
443
+ expectedBrief: " Protocol P foo1 " ,
444
+ expectedFull: """
445
+ <Function file= " \( path) " line= " 3 " column= " 8 " > \
446
+ <Name>foo1()</Name> \
447
+ <USR>s:1a1PP4foo1yyF</USR> \
448
+ <Declaration>func foo1()</Declaration> \
449
+ <CommentParts> \
450
+ <Abstract><Para>Protocol P foo1</Para></Abstract> \
451
+ <Discussion><Note> \
452
+ <Para>This documentation comment was inherited from <codeVoice>P</codeVoice>.</Para> \
453
+ </Note></Discussion> \
454
+ </CommentParts> \
455
+ </Function>
456
+ """
457
+ )
453
458
XCTAssertEqual ( sym1Doc. associatedUSRs, [ " s:1a1SV4foo1yyF " , " s:1a1PP4foo1yyF " ] )
454
459
455
460
let sym2Doc = try await sourcekitd. completeDocumentation ( id: sym2. id)
456
- XCTAssertEqual ( sym2Doc. docFullAsXML,
457
- """
458
- <Function file= " \( path) " line= " 8 " column= " 8 " > \
459
- <Name>foo2()</Name> \
460
- <USR>s:1a1SV4foo2yyF</USR> \
461
- <Declaration>func foo2()</Declaration> \
462
- <CommentParts> \
463
- <Abstract><Para>Struct S foo2</Para></Abstract> \
464
- </CommentParts> \
465
- </Function>
466
- """ )
461
+ assertDocumentation (
462
+ full: sourcekitd. supportsFullDocumentationInCompletion,
463
+ documentation: sym2Doc,
464
+ expectedBrief: " Struct S foo2 " ,
465
+ expectedFull: """
466
+ <Function file= " \( path) " line= " 8 " column= " 8 " > \
467
+ <Name>foo2()</Name> \
468
+ <USR>s:1a1SV4foo2yyF</USR> \
469
+ <Declaration>func foo2()</Declaration> \
470
+ <CommentParts> \
471
+ <Abstract><Para>Struct S foo2</Para></Abstract> \
472
+ </CommentParts> \
473
+ </Function>
474
+ """
475
+ )
467
476
XCTAssertEqual ( sym2Doc. associatedUSRs, [ " s:1a1SV4foo2yyF " ] )
468
477
469
478
let sym3Doc = try await sourcekitd. completeDocumentation ( id: sym3. id)
470
479
XCTAssertNil ( sym3Doc. docFullAsXML)
480
+ XCTAssertNil ( sym3Doc. docBrief)
471
481
XCTAssertEqual ( sym3Doc. associatedUSRs, [ " s:1a1SV4foo3yyF " ] )
472
482
}
473
483
@@ -1789,11 +1799,13 @@ fileprivate struct CompletionResult: Equatable, Sendable {
1789
1799
}
1790
1800
1791
1801
fileprivate struct CompletionDocumentation {
1802
+ var docBrief : String ? = nil
1792
1803
var docFullAsXML : String ? = nil
1793
1804
var associatedUSRs : [ String ] = [ ]
1794
1805
1795
1806
init ( _ dict: SKDResponseDictionary ) {
1796
1807
let keys = dict. sourcekitd. keys
1808
+ self . docBrief = dict [ keys. docBrief]
1797
1809
self . docFullAsXML = dict [ keys. docFullAsXML]
1798
1810
self . associatedUSRs = dict [ keys. associatedUSRs] ? . asStringArray ?? [ ]
1799
1811
}
@@ -2072,6 +2084,10 @@ fileprivate extension SourceKitD {
2072
2084
try await openDocument ( path, contents: textWithoutMarker, compilerArguments: [ path] )
2073
2085
return ( positions [ " 1️⃣ " ] , recent)
2074
2086
}
2087
+
2088
+ nonisolated var supportsFullDocumentationInCompletion : Bool {
2089
+ return ideApi. completion_item_get_doc_full_copy != nil
2090
+ }
2075
2091
}
2076
2092
2077
2093
private struct ExpectationNotFulfilledError : Error { }
@@ -2094,3 +2110,21 @@ private func runAsync<T: Sendable>(_ body: @escaping @Sendable () async throws -
2094
2110
}
2095
2111
return try result. get ( )
2096
2112
}
2113
+
2114
+ /// Asserts that documentation matches the expected values based on whether full documentation is supported in sourcekitd or not.
2115
+ private func assertDocumentation(
2116
+ full: Bool ,
2117
+ documentation: CompletionDocumentation ,
2118
+ expectedBrief: String ,
2119
+ expectedFull: String ,
2120
+ file: StaticString = #filePath,
2121
+ line: UInt = #line
2122
+ ) {
2123
+ if full {
2124
+ XCTAssertEqual ( documentation. docFullAsXML, expectedFull, file: file, line: line)
2125
+ XCTAssertNil ( documentation. docBrief, " Expected brief documentation to not be available " , file: file, line: line)
2126
+ } else {
2127
+ XCTAssertEqual ( documentation. docBrief, expectedBrief, file: file, line: line)
2128
+ XCTAssertNil ( documentation. docFullAsXML, " Expected full documentation to not be available " , file: file, line: line)
2129
+ }
2130
+ }
0 commit comments