Skip to content

Commit 9c91d10

Browse files
authored
Omit whitespace from suggested link completion disambiguations (#1232)
rdar://152496072
1 parent b76e07f commit 9c91d10

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Sources/SwiftDocC/DocumentationService/Convert/Symbol Link Resolution/LinkCompletionTools.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public enum LinkCompletionTools {
131131
node,
132132
kind: symbol.kind,
133133
hash: symbol.symbolIDHash,
134-
parameterTypes: symbol.parameterTypes,
135-
returnTypes: symbol.returnTypes
134+
parameterTypes: symbol.parameterTypes?.map { $0.withoutWhitespace() },
135+
returnTypes: symbol.returnTypes?.map { $0.withoutWhitespace() }
136136
)
137137
}
138138

@@ -236,3 +236,9 @@ private extension PathHierarchy.PathComponent.Disambiguation {
236236
}
237237
}
238238
}
239+
240+
private extension String {
241+
func withoutWhitespace() -> String {
242+
filter { !$0.isWhitespace }
243+
}
244+
}

Tests/SwiftDocCTests/Infrastructure/Symbol Link Resolution/LinkCompletionToolsTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,25 @@ class LinkCompletionToolsTests: XCTestCase {
237237
"->_", // The only overload that returns something
238238
])
239239
}
240+
241+
func testRemovesWhitespaceFromTypeSignatureDisambiguation() {
242+
let overloads = [
243+
// The caller included whitespace in these closure type spellings but the DocC disambiguation won't include this whitespace.
244+
(parameters: ["(Int) -> Int"], returns: []), // ((Int) -> Int) -> Void
245+
(parameters: ["(Bool) -> ()"], returns: []), // ((Bool) -> () ) -> Void
246+
].map {
247+
LinkCompletionTools.SymbolInformation(
248+
kind: "func",
249+
symbolIDHash: "\($0)".stableHashString,
250+
parameterTypes: $0.parameters,
251+
returnTypes: $0.returns
252+
)
253+
}
254+
255+
XCTAssertEqual(LinkCompletionTools.suggestedDisambiguation(forCollidingSymbols: overloads), [
256+
// Both parameters require the only parameter type as disambiguation. The suggested disambiguation shouldn't contain extra whitespace.
257+
"-((Int)->Int)",
258+
"-((Bool)->())",
259+
])
260+
}
240261
}

0 commit comments

Comments
 (0)