@@ -427,19 +427,31 @@ class SourceKitDocument {
427
427
private func checkExpectedCompletionResult( _ expected: ExpectedResult , in response: SourceKitdResponse , info: RequestInfo ) throws {
428
428
let matcher = CompletionMatcher ( for: expected)
429
429
var found = false
430
+ var foundDuplicate : String ? = nil
431
+ var seenResults = Set < String > ( )
430
432
response. value. getArray ( . key_Results) . enumerate { ( _, item) -> Bool in
431
433
let result = item. getDictionary ( )
432
434
found = matcher. match ( result. getString ( . key_Name) , ignoreArgLabels: shouldIgnoreArgs ( of: expected, for: result) )
435
+ let description = result. getString ( . key_Description)
436
+ if foundDuplicate == nil , !seenResults. insert ( description) . inserted {
437
+ foundDuplicate = description
438
+ }
433
439
return !found
434
440
}
435
- if !found {
441
+ lazy var truncatedResponseText = {
436
442
// FIXME: code completion responses can be huge, truncate them for now.
437
443
let maxSize = 25_000
438
444
var responseText = response. description
439
445
if responseText. count > maxSize {
440
446
responseText = responseText. prefix ( maxSize) + " [truncated] "
441
447
}
442
- throw SourceKitError . failed ( . missingExpectedResult, request: info, response: responseText. trimmingCharacters ( in: . newlines) )
448
+ return responseText
449
+ } ( )
450
+ if !found {
451
+ throw SourceKitError . failed ( . missingExpectedResult, request: info, response: truncatedResponseText. trimmingCharacters ( in: . newlines) )
452
+ }
453
+ if let foundDuplicate = foundDuplicate {
454
+ throw SourceKitError . failed ( . duplicateResult( name: foundDuplicate) , request: info, response: truncatedResponseText. trimmingCharacters ( in: . newlines) )
443
455
}
444
456
}
445
457
0 commit comments