Skip to content

Commit 26475de

Browse files
address more review comments
1 parent 1a6b818 commit 26475de

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

Sources/SourceKitLSP/Swift/OnDiskDocumentManager.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ actor OnDiskDocumentManager: Sendable {
2727
private weak var sourceKitLSPServer: SourceKitLSPServer?
2828
private var openSnapshots: [DocumentURI: (snapshot: DocumentSnapshot, patchedCompileCommand: SwiftCompileCommand?)]
2929

30-
init(sourceKitLSPServer: SourceKitLSPServer) {
30+
fileprivate init(sourceKitLSPServer: SourceKitLSPServer) {
3131
self.sourceKitLSPServer = sourceKitLSPServer
3232
self.openSnapshots = [:]
3333
}
@@ -38,7 +38,7 @@ actor OnDiskDocumentManager: Sendable {
3838
///
3939
/// - Parameter symbolLocation: The location of the symbol to fetch the symbol graph for.
4040
func fetchSymbolGraph(at symbolLocation: SymbolLocation) async throws -> String? {
41-
let (snapshot, patchedCompileCommand) = try await openDocumentSnapshot(at: symbolLocation)
41+
let (snapshot, patchedCompileCommand) = try await openDocumentSnapshot(for: symbolLocation.documentUri)
4242
let swiftLanguageService = try await swiftLanguageService(for: symbolLocation.documentUri)
4343
return try await swiftLanguageService.cursorInfo(
4444
snapshot,
@@ -48,19 +48,6 @@ actor OnDiskDocumentManager: Sendable {
4848
).symbolGraph
4949
}
5050

51-
/// Open a unique dummy document in sourcekitd that has the contents of the file on disk for uri, but an arbitrary
52-
/// URI which doesn't exist on disk.
53-
///
54-
/// The document will be retained until ``closeAllDocuments()`` is called. This will avoid parsing the same
55-
/// document multiple times if more than one symbol needs to be looked up.
56-
///
57-
/// - Parameter symbolLocation: The location of the document that will be opened.
58-
func openDocumentSnapshot(
59-
at symbolLocation: SymbolLocation
60-
) async throws -> (snapshot: DocumentSnapshot, patchedCompileCommand: SwiftCompileCommand?) {
61-
try await openDocumentSnapshot(for: symbolLocation.documentUri)
62-
}
63-
6451
/// Open a unique dummy document in sourcekitd that has the contents of the file on disk for uri, but an arbitrary
6552
/// URI which doesn't exist on disk.
6653
///
@@ -71,16 +58,16 @@ actor OnDiskDocumentManager: Sendable {
7158
func openDocumentSnapshot(
7259
for uri: DocumentURI
7360
) async throws -> (snapshot: DocumentSnapshot, patchedCompileCommand: SwiftCompileCommand?) {
74-
guard let cachedSnapshot = openSnapshots[uri] else {
75-
let languageService = try await swiftLanguageService(for: uri)
76-
let snapshot = try await languageService.openSnapshotFromDiskOpenedInSourcekitd(
77-
uri: uri,
78-
fallbackSettingsAfterTimeout: false
79-
)
80-
openSnapshots[uri] = snapshot
81-
return snapshot
61+
if let cachedSnapshot = openSnapshots[uri] {
62+
return cachedSnapshot
8263
}
83-
return cachedSnapshot
64+
let languageService = try await swiftLanguageService(for: uri)
65+
let snapshot = try await languageService.openSnapshotFromDiskOpenedInSourcekitd(
66+
uri: uri,
67+
fallbackSettingsAfterTimeout: false
68+
)
69+
openSnapshots[uri] = snapshot
70+
return snapshot
8471
}
8572

8673
/// Closes all document snapshots that were opened by this ``OnDiskDocumentManager``.

0 commit comments

Comments
 (0)