Show warning for Swiftly/Xcode toolchain mismatch failures#2109
Show warning for Swiftly/Xcode toolchain mismatch failures#2109Flamki wants to merge 3 commits intoswiftlang:mainfrom
Conversation
|
Implemented a fix for this in PR #2109. Approach taken:
This should replace many currently cryptic mismatch errors with a clear, guided warning for users. |
rbenegal
left a comment
There was a problem hiding this comment.
Thanks very much for this @Flamki! I think having something like this would be very helpful for folks who have multiple toolchains installed.
Left some comments for your thoughts, and I think it would be great if @matthewbastien also took a look at this and share some thoughts.
| lowerOutput.includes("xcodedefault.xctoolchain") || | ||
| lowerOutput.includes("/applications/xcode") || | ||
| lowerOutput.includes("contents/developer/toolchains"); | ||
| const hasVersionMismatchSignal = [ |
There was a problem hiding this comment.
Curious to know how you came up with this list. Is this based on actual diagnostics that are emitted by the compiler? Wondering if it would be best to always rely on different version numbers as a signal.
There was a problem hiding this comment.
Great question. The list came from real mismatch failure logs we saw (module/compiler version errors, swift-frontend failures, mixed toolchain paths), plus conservative fallbacks. I kept swiftlang-* version mismatch as a strong signal, but not the only signal, because many real logs don’t always include two parseable version strings. I can tighten this further toward version-first if maintainers prefer.
| let lastDiagnosticNeedsSaving = false; | ||
| disposables.push( | ||
| swiftExecution.onDidWrite(data => { | ||
| const sanitizedData = (remainingData || "") + stripAnsi(data); |
There was a problem hiding this comment.
Is there a reason this portion had to change?
There was a problem hiding this comment.
Yes, this change is intentional. I needed the raw task output chunk (stripAnsi(data)) in a bounded buffer so we can run mismatch detection at task completion for build/test/run failures. Without this, we only catch package-load errors and miss the most common runtime/task failure path.
| }); | ||
| } | ||
|
|
||
| private folderContextForTask(task: vscode.Task): FolderContext | undefined { |
There was a problem hiding this comment.
Also not sure why this folderContextForTask portion is required here. Is this being used to ensure that the warning is not shown again for the same folder somehow?
There was a problem hiding this comment.
Exactly. folderContextForTask ensures we map a task failure to the correct folder in multi-root workspaces, so warning dedupe is per-folder and the detector uses the right toolchain manager (swiftly vs others). Relying on currentFolder can point to the wrong workspace folder during background task runs.
| let outputBuffer = ""; | ||
| const done = () => { | ||
| if (folderContext && outputBuffer.length > 0) { | ||
| maybeShowSwiftlyXcodeToolchainMismatchWarning(outputBuffer, folderContext); |
There was a problem hiding this comment.
This is very interesting thanks! I was not thinking of parsing diagnostics, initially was just thinking we could base it on detecting different version numbers, but I think a problem that was brought up with that is sometimes the builds will work fine even if there is a slight mismatch (i.e. modules built with an older version that works fine with newer versions) so perhaps this approach is better.
|
@rbenegal Pushed a follow-up commit to this PR: What changed:
Responses to review questions:
I’ll keep an eye on the re-run checks and adjust further if anything else pops up. |
|
Merged For the conflict resolution, I kept both important parts:
I also ran Prettier on the merged file. Local checks after resolving:
Both pass locally. |
Description
This PR fixes issue #2075 by detecting likely version mismatches between Swiftly-managed Swift toolchains and the selected Xcode toolchain, then showing a targeted warning with clear next actions.
In mismatch scenarios users can currently see cryptic build/package errors. With this change, the extension now surfaces a warning that explains the likely cause and suggests resolution paths:
Issue: #2075
What Changed
toolchainMismatchdetection/warning module:detectSwiftlyXcodeToolchainMismatch(...)maybeShowSwiftlyXcodeToolchainMismatchWarning(...)Select Toolchain,Open Documentation)swift-frontend command failed, differingswiftlang-*versions)Tasks
Testing
npm run lintnpm run unit-testBoth commands pass locally.