Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Sources/SourceKitLSP/SourceKitLSPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1733,10 +1733,21 @@ extension SourceKitLSPServer {
}()
)
for workspace in workspaces {
let mainFile = await workspace.buildServerManager
var candidateMainFiles = await workspace.buildServerManager
.mainFiles(containing: moduleFileURI)
.sorted(by: { $0.arbitrarySchemeURL.absoluteString < $1.arbitrarySchemeURL.absoluteString })
.first
if candidateMainFiles.isEmpty {
// SDK module files don't necessarily have a recorded main-file relationship in the index. We only need a Swift
// source file from the workspace to provide compiler arguments for generating the interface.
candidateMainFiles =
await orLog("Getting Swift source files for workspaceSymbol/resolve generated interface") {
try await workspace.buildServerManager.projectSourceFiles()
.keys
.filter { $0.fileURL?.pathExtension == "swift" }
.sorted(by: { $0.arbitrarySchemeURL.absoluteString < $1.arbitrarySchemeURL.absoluteString })
} ?? []
}
let mainFile = candidateMainFiles.first
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn’t seem correct. A project may contain some files that are built for eg. the iOS SDK while others that are built for the watchOS SDK and you can’t open a module from the iOS SDK with build settings from the watchOS SDK.

What’s the exact issue that you’re seeing here? Do you have a test case that reproduces it?

guard let mainFile else {
continue
}
Expand Down