Skip to content

SourceKitLSP: fallback to Swift source for SDK symbol resolve#2664

Open
compnerd wants to merge 1 commit into
swiftlang:mainfrom
compnerd:indexing
Open

SourceKitLSP: fallback to Swift source for SDK symbol resolve#2664
compnerd wants to merge 1 commit into
swiftlang:mainfrom
compnerd:indexing

Conversation

@compnerd
Copy link
Copy Markdown
Member

When resolving a workspace symbol whose location points at an SDK .swiftmodule/.swiftinterface, SourceKit-LSP currently asks IndexStoreDB for main files containing that module file and uses one of those files to provide build settings for opening the generated interface.

That relationship is not guaranteed to exist for SDK module files. The module file can appear as the indexed symbol location, while mainFiles(containing:) still returns no source file. This causes workspaceSymbol/resolve to fail before calling sourcekitd, with errors like:

No source file found that imports Swift.String; cannot open generated interface

If no main file is found for the module file, fall back to a buildable Swift source file from the workspace. The file is only used as the source of compiler arguments for generating the interface, so any buildable Swift source in the workspace is sufficient.

This fixes resolving stdlib/SDK workspace symbols such as Swift.String on Windows SDK layouts where the stdlib location is a .swiftmodule under the SDK.

When resolving a workspace symbol whose location points at an SDK
.swiftmodule/.swiftinterface, SourceKit-LSP currently asks IndexStoreDB for
main files containing that module file and uses one of those files to provide
build settings for opening the generated interface.

That relationship is not guaranteed to exist for SDK module files. The module
file can appear as the indexed symbol location, while
mainFiles(containing:) still returns no source file. This causes
workspaceSymbol/resolve to fail before calling sourcekitd, with errors like:

  No source file found that imports Swift.String; cannot open generated interface

If no main file is found for the module file, fall back to a buildable Swift
source file from the workspace. The file is only used as the source of compiler
arguments for generating the interface, so any buildable Swift source in the
workspace is sufficient.

This fixes resolving stdlib/SDK workspace symbols such as Swift.String on
Windows SDK layouts where the stdlib location is a .swiftmodule under the SDK.
@compnerd
Copy link
Copy Markdown
Member Author

@swift-ci please test

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 22, 2026

The file is only used as the source of compiler arguments for generating the interface, so any buildable Swift source in the workspace is sufficient.

Not always. Some build server can support multiple targets for different platforms.

IMO, the right fix is, when no workspace doesn't have a main file for it, use .swiftmodule/.swiftinterface as the .buildSettingsFile, then infer the fallback compiler arguments in openGeneratedInterface().

How?

  • -target: If the module is named <Name>.swiftmodule/<arch>.{swiftmodule|swiftinterface}, use the triple to derive it
  • -sdk: infer it from the path of the module, fallback to relative path to a toolchain used in the workspace
  • -F {path} for {path}/<Name>.framework/Modules/... , or -I {path} for {path}/<Name>.swiftmodule/...

@rintaro
Copy link
Copy Markdown
Member

rintaro commented May 22, 2026

If this is blocking something for Windows, feel free to disable it for Windows for now.

@compnerd
Copy link
Copy Markdown
Member Author

The current desire is for testing, but it seems that the test suite passed on CI, so I can hold off on this until someone has time to look into your recommendation

.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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants