Skip to content

Commit e3d0ade

Browse files
author
Wang Lun
committed
fix: prevent duplicating interface
1 parent b316cd7 commit e3d0ade

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,31 +2072,7 @@ extension SourceKitLSPServer {
20722072
originatorUri: DocumentURI,
20732073
languageService: LanguageService
20742074
) async throws -> Location {
2075-
// Check if we're already in the target interface with the same module/group/symbol
2076-
if case .generatedInterface(let interfaceData) = try? ReferenceDocumentURL(from: originatorUri),
2077-
interfaceData.moduleName == moduleName && interfaceData.groupName == groupName
2078-
{
2079-
// If we have a specific symbol USR, try to find its position in the current interface
2080-
if let symbolUSR = symbolUSR,
2081-
let swiftLanguageService = languageService as? SwiftLanguageService
2082-
{
2083-
do {
2084-
let position = try await swiftLanguageService.generatedInterfaceManager.position(
2085-
ofUsr: symbolUSR,
2086-
in: interfaceData
2087-
)
2088-
return Location(uri: originatorUri, range: Range(position))
2089-
} catch {
2090-
// If we can't find the symbol, just return the top of the current interface
2091-
return Location(uri: originatorUri, range: Range(Position(line: 0, utf16index: 0)))
2092-
}
2093-
} else {
2094-
// No specific symbol, just return the current interface location
2095-
return Location(uri: originatorUri, range: Range(Position(line: 0, utf16index: 0)))
2096-
}
2097-
}
2098-
2099-
// If the originator URI is already a generated interface, use its primary file for build settings
2075+
// Let openGeneratedInterface handle all the logic, including checking if we're already in the right interface
21002076
let documentForBuildSettings = originatorUri.buildSettingsFile
21012077

21022078
guard

Sources/SwiftLanguageService/OpenInterface.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ extension SwiftLanguageService {
2222
groupName: String?,
2323
symbolUSR symbol: String?
2424
) async throws -> GeneratedInterfaceDetails? {
25+
// Include build settings context to distinguish different versions/configurations
26+
let buildSettingsFileHash = "\(abs(document.buildSettingsFile.stringValue.hashValue))"
27+
let sourcekitdDocumentName = [moduleName, groupName, buildSettingsFileHash].compactMap(\.self).joined(
28+
separator: "."
29+
)
30+
2531
let urlData = GeneratedInterfaceDocumentURLData(
2632
moduleName: moduleName,
2733
groupName: groupName,
28-
sourcekitdDocumentName: "\(moduleName)-\(UUID())",
34+
sourcekitdDocumentName: sourcekitdDocumentName,
2935
primaryFile: document
3036
)
3137
let position: Position? =

0 commit comments

Comments
 (0)