Skip to content

Commit b09c7d4

Browse files
address review comments
1 parent 2f2879e commit b09c7d4

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

Sources/DocCDocumentation/IndexStoreDB+Extensions.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ extension CheckedIndex {
2525
/// the same result every time.
2626
package func primaryDefinitionOrDeclarationOccurrence(
2727
ofDocCSymbolLink symbolLink: DocCSymbolLink,
28-
fetchSymbolGraph: @Sendable (_: SymbolLocation) async throws -> String?
28+
fetchSymbolGraph: @Sendable (SymbolLocation) async throws -> String?
2929
) async throws -> SymbolOccurrence? {
30-
guard !symbolLink.components.isEmpty else {
31-
return nil
30+
guard let topLevelSymbolName = symbolLink.components.last?.name else {
31+
throw DocCCheckedIndexError.emptyDocCSymbolLink
3232
}
3333
// Find all occurrences of the symbol by name alone
34-
let topLevelSymbolName = symbolLink.components.last!.name
3534
var topLevelSymbolOccurrences: [SymbolOccurrence] = []
3635
forEachCanonicalSymbolOccurrence(byName: topLevelSymbolName) { symbolOccurrence in
3736
topLevelSymbolOccurrences.append(symbolOccurrence)
@@ -60,7 +59,7 @@ extension CheckedIndex {
6059
/// - fetchSymbolGraph: Callback that returns a SymbolGraph for a given SymbolLocation
6160
package func doccSymbolInformation(
6261
ofUSR usr: String,
63-
fetchSymbolGraph: (_: SymbolLocation) async throws -> String?
62+
fetchSymbolGraph: (SymbolLocation) async throws -> String?
6463
) async throws -> DocCSymbolInformation? {
6564
guard let topLevelSymbolOccurrence = primaryDefinitionOrDeclarationOccurrence(ofUSR: usr) else {
6665
return nil
@@ -77,18 +76,35 @@ extension CheckedIndex {
7776
var components = [DocCSymbolInformation.Component(fromModuleName: moduleName)]
7877
for symbolOccurence in symbols {
7978
guard let rawSymbolGraph = try await fetchSymbolGraph(symbolOccurence.location) else {
80-
return nil
79+
throw DocCCheckedIndexError.noSymbolGraph(symbolOccurence.symbol.usr)
8180
}
8281
let symbolGraph = try JSONDecoder().decode(SymbolGraph.self, from: Data(rawSymbolGraph.utf8))
8382
guard let symbol = symbolGraph.symbols[symbolOccurence.symbol.usr] else {
84-
return nil
83+
throw DocCCheckedIndexError.symbolNotFound(symbolOccurence.symbol.usr)
8584
}
8685
components.append(DocCSymbolInformation.Component(fromSymbol: symbol))
8786
}
8887
return DocCSymbolInformation(components: components)
8988
}
9089
}
9190

91+
enum DocCCheckedIndexError: LocalizedError {
92+
case emptyDocCSymbolLink
93+
case noSymbolGraph(String)
94+
case symbolNotFound(String)
95+
96+
var errorDescription: String? {
97+
switch self {
98+
case .emptyDocCSymbolLink:
99+
"The provided DocCSymbolLink was empty and could not be resolved"
100+
case .noSymbolGraph(let usr):
101+
"Unable to locate symbol graph for \(usr)"
102+
case .symbolNotFound(let usr):
103+
"Symbol \(usr) was not found in its symbol graph"
104+
}
105+
}
106+
}
107+
92108
extension SymbolOccurrence {
93109
func parent(_ index: CheckedIndex) -> SymbolOccurrence? {
94110
let allParentRelations =

Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ extension DocumentationLanguageService {
7171
return try await languageService.withSnapshotFromDiskOpenedInSourcekitd(
7272
uri: location.documentUri,
7373
fallbackSettingsAfterTimeout: false
74-
) {
75-
(snapshot, compileCommand) in
74+
) { (snapshot, compileCommand) in
7675
let (_, _, symbolGraph) = try await languageService.cursorInfo(
7776
snapshot,
7877
compileCommand: compileCommand,

Sources/SourceKitLSP/Swift/DoccDocumentation.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ extension SwiftLanguageService {
7979
try await withSnapshotFromDiskOpenedInSourcekitd(
8080
uri: symbolLocation.documentUri,
8181
fallbackSettingsAfterTimeout: false
82-
) {
83-
(snapshot, compileCommand) in
82+
) { (snapshot, compileCommand) in
8483
let (_, _, symbolGraph) = try await self.cursorInfo(
8584
snapshot,
8685
compileCommand: compileCommand,
@@ -107,7 +106,7 @@ extension SwiftLanguageService {
107106
documentationManager: DocCDocumentationManager,
108107
catalogURL: URL?,
109108
for symbolUSR: String,
110-
fetchSymbolGraph: @Sendable (_: SymbolLocation) async throws -> String?
109+
fetchSymbolGraph: @Sendable (SymbolLocation) async throws -> String?
111110
) async throws -> String? {
112111
guard let catalogURL else {
113112
return nil

0 commit comments

Comments
 (0)