Skip to content

Commit 1355b20

Browse files
committed
Use on-disk contents of a source file to get the position of a symbol occurrence
The index refers to on-disk locations and since the cursor info below also operates on the on-disk contents, we should use the on-disk contents of the file to convert the symbol occurrence location to a `Position`.
1 parent 024efc2 commit 1355b20

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,22 @@ extension DocumentationLanguageService {
6363
else {
6464
throw ResponseError.requestFailed(doccDocumentationError: .symbolNotFound(symbolName))
6565
}
66+
let symbolDocumentUri = symbolOccurrence.location.documentUri
6667
guard
67-
let symbolWorkspace = try await workspaceForDocument(uri: symbolOccurrence.location.documentUri),
68-
let languageService = try await languageService(
69-
for: symbolOccurrence.location.documentUri,
70-
.swift,
71-
in: symbolWorkspace
72-
) as? SwiftLanguageService,
73-
let symbolSnapshot = try documentManager.latestSnapshotOrDisk(
74-
symbolOccurrence.location.documentUri,
75-
language: .swift
76-
)
68+
let symbolWorkspace = try await workspaceForDocument(uri: symbolDocumentUri),
69+
let languageService = try await languageService(for: symbolDocumentUri, .swift, in: symbolWorkspace)
70+
as? SwiftLanguageService
7771
else {
78-
throw ResponseError.internalError(
79-
"Unable to find Swift language service for \(symbolOccurrence.location.documentUri)"
80-
)
72+
throw ResponseError.internalError("Unable to find Swift language service for \(symbolDocumentUri)")
8173
}
82-
let position = symbolSnapshot.position(of: symbolOccurrence.location)
8374
let symbolGraph = try await languageService.withSnapshotFromDiskOpenedInSourcekitd(
84-
uri: symbolOccurrence.location.documentUri,
75+
uri: symbolDocumentUri,
8576
fallbackSettingsAfterTimeout: false
8677
) { snapshot, compileCommand in
8778
try await languageService.cursorInfo(
8879
snapshot,
8980
compileCommand: compileCommand,
90-
Range(position),
81+
Range(snapshot.position(of: symbolOccurrence.location)),
9182
includeSymbolGraph: true
9283
).symbolGraph
9384
}

0 commit comments

Comments
 (0)