Skip to content

Commit 6f214ea

Browse files
author
Wang Lun
committed
fix: prevent duplicating interface
1 parent 00cfa79 commit 6f214ea

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
@@ -2065,31 +2065,7 @@ extension SourceKitLSPServer {
20652065
originatorUri: DocumentURI,
20662066
languageService: LanguageService
20672067
) async throws -> Location {
2068-
// Check if we're already in the target interface with the same module/group/symbol
2069-
if case .generatedInterface(let interfaceData) = try? ReferenceDocumentURL(from: originatorUri),
2070-
interfaceData.moduleName == moduleName && interfaceData.groupName == groupName
2071-
{
2072-
// If we have a specific symbol USR, try to find its position in the current interface
2073-
if let symbolUSR = symbolUSR,
2074-
let swiftLanguageService = languageService as? SwiftLanguageService
2075-
{
2076-
do {
2077-
let position = try await swiftLanguageService.generatedInterfaceManager.position(
2078-
ofUsr: symbolUSR,
2079-
in: interfaceData
2080-
)
2081-
return Location(uri: originatorUri, range: Range(position))
2082-
} catch {
2083-
// If we can't find the symbol, just return the top of the current interface
2084-
return Location(uri: originatorUri, range: Range(Position(line: 0, utf16index: 0)))
2085-
}
2086-
} else {
2087-
// No specific symbol, just return the current interface location
2088-
return Location(uri: originatorUri, range: Range(Position(line: 0, utf16index: 0)))
2089-
}
2090-
}
2091-
2092-
// If the originator URI is already a generated interface, use its primary file for build settings
2068+
// Let openGeneratedInterface handle all the logic, including checking if we're already in the right interface
20932069
let documentForBuildSettings = originatorUri.buildSettingsFile
20942070

20952071
guard

Sources/SourceKitLSP/Swift/OpenInterface.swift

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

0 commit comments

Comments
 (0)