Refactor Pico project activation around project variants#260
Open
gonzalolarralde wants to merge 6 commits intoraspberrypi:mainfrom
Open
Refactor Pico project activation around project variants#260gonzalolarralde wants to merge 6 commits intoraspberrypi:mainfrom
gonzalolarralde wants to merge 6 commits intoraspberrypi:mainfrom
Conversation
Add explicit managed-tool path checking and improve variant detection and error handling. - Introduce isManagedToolPath and use it in selectedManagedToolVersion/ensureManagedTool to reliably detect managed CMake/Ninja paths and log/return on missing parsed versions (src/projectVariants/common.mts). - In Zephyr variant, validate that managed tool paths yield versions and fail with a logged error if they don't (src/projectVariants/zephyrVariant.mts). - Update project variant registry detection to prefer import candidates over the first unsupported fallback (src/projectVariants/registry.mts). - Update getPaths logic to handle Rust toolchain selection, improve error messages for unsupported toolchains/Zephyr boards, and factor out showProjectChipError which reports unsupported Zephyr boards using named constants (src/commands/getPaths.mts). - Minor import and formatting adjustments related to the above changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello all, I'm working on a proposal to add Swift support to the VSCode extension. While working on that I realized there was an opportunity to make project activation and settings detection a bit more abstract, untangling some of the code in
extension.mtswhile preserving functionality.I opened the issue #259 to describe the problem, this PR is an implementation proposal. I hope the change size is manageable. I'd be happy to change the approach or break down the PR further if that would help readability.
I've been running a couple test cases and seems to preserve the existing behavior as expected. I verified:
Tests included, when applicable: setting board, chip, sdk version, configure CMake, proper handling of non-pico projects.
Summary
This PR refactors project detection and activation around a small project-variant interface for the existing Pico project types: C/C++, Rust, and Zephyr.
The goal is not to change user-visible behavior. It is to make the current behavior easier to follow before adding another project type. Previously, activation mixed project detection, selected SDK/toolchain/board parsing, dependency setup, status bar updates, CMake setup, Rust setup, and Zephyr setup in one large flow. That made it difficult to see which parts were shared across project types and which parts were specific to one variant.
This change separates those responsibilities while keeping compatibility with the existing flows.
What Changed
Added a project variant registry and per-variant implementations for:
Moved C/C++ activation behavior into
CCppProjectVariant, including:Moved shared Pico dependency setup into
utils/picoDependencies.mtsso SDK, toolchain, tools, picotool, and OpenOCD setup are not tied to only one project type.Kept Zephyr as a compatibility wrapper around the existing
setupZephyrflow. This avoids changing the deeper Zephyr setup behavior in this PR while still making activation use the same project-variant structure.Updated path/helper commands to resolve chip, target, SDK, and toolchain information through project variant helpers instead of duplicating project-type checks in each command.
Why
This prepares the extension for adding another project type without adding more special cases to activation and command handlers.
The main design idea is:
That makes the relationship between old and new behavior clearer and gives future project types a defined place to plug in.
Compatibility Notes
This PR intentionally preserves the existing behavior for supported project types:
.pico-rsand the latest version bundle behavior.setupZephyrimplementation.pico_sdk_init()but are not extension-managed yet.getChip,getTarget,getGDBPath, compiler paths, SVD path, and Zephyr paths is retained.