Skip to content

feat(vscode): provide verified clangd and Microsoft C/C++ IntelliSense for WASM sketches #203

Closed

Description

@zackees

??## Context

FastLED WASM needs IntelliSense to work in a fresh desktop VS Code installation whether or not the optional clangd extension is installed. The current implementation is clangd-only and the proposed VS Code extension does not currently configure either engine:

  • crates/fastled-cli/src/clangd_config.rs writes compile_commands.json, .clangd, and .vscode/settings.json only after fastled --clangd or fastled --write-clangd.
  • The generated settings explicitly set C_Cpp.intelliSenseEngine, C_Cpp.autocomplete, and C_Cpp.errorSquiggles to disabled, so a user without clangd gets no C++ language service.
  • vscode-plugin/src/extension.ts never invokes either opt-in CLI path and has no configure/refresh lifecycle.
  • vscode-plugin/package.json declares neither ms-vscode.cpptools nor llvm-vs-code-extensions.vscode-clangd as a dependency.

The current compilation database is also not a verified representation of the real compiler invocation. A Windows Blink smoke test with the installed fastled 2.0.13 CLI generated two entries, but executing both emitted commands failed:

  • the .ino entry omitted Emscripten's compatibility include sequence and failed while resolving libc++ xlocale.h;
  • the generated wrapper also removed the PCM/module arguments needed for import "wasm_pch.h";
  • filter_compile_flags() deliberately removes every -Xclang pair and -fmodule-file=..., while the current direct-Clang build path obtains required backend flags from em++ --cflags, including -Xclang -iwithsysroot/include\\compat and FakeSDL include paths.

The unit tests currently prove JSON shape and stable filtering, but not that a database entry matches or can successfully execute the production compile plan. This drift is especially likely after the direct-Clang changes in #191 and #192.

PlatformIO provides the relevant prior art:

  • the PlatformIO VS Code extension declares "extensionDependencies": ["ms-vscode.cpptools"], so installing PlatformIO also installs Microsoft C/C++;
  • PlatformIO Core first constructs engine-neutral idedata containing compiler paths, C/C++ flags, defines, build/library/toolchain includes, and forced includes;
  • pio project init --ide vscode renders that metadata into .vscode/c_cpp_properties.json with includePath, browse.path, defines, forcedInclude, compilerPath, compilerArgs, and language standards;
  • pio run --target compiledb emits the compilation database separately.

A real minimal PlatformIO native smoke project confirmed this behavior: project initialization generated c_cpp_properties.json backed by idedata.json, and the separate compiledb target generated an executable compiler command.

Microsoft C/C++ supports compileCommands in c_cpp_properties.json; a matching translation unit uses the database entry while includePath, defines, compilerPath, compilerArgs, forcedInclude, and browse.path remain important for standalone headers and files without a matching entry. Its public custom-configuration-provider API could avoid generated files, but the PlatformIO-style file approach is easier to inspect, reproduce, and acceptance-test for the first implementation.

Sources:

Proposal

1. Derive all editor metadata from one production compile plan

Introduce one engine-neutral SketchCompilePlan (name illustrative) in the Rust build layer. It should contain the compiler executable, working directory, translation units, exact compile arguments, includes by scope, defines, forced includes/module prerequisites, language standard, and target/sysroot information.

The real direct-Clang build, compile_commands.json, clangd fallback configuration, and Microsoft C/C++ configuration must all derive from this object. Do not independently reconstruct flags in clangd_config.rs. Preserve arguments that are required to parse the source; only remove output/dependency-emission arguments when an editor-specific view genuinely requires it, and test every transformation.

2. Emit a valid compilation database

Generate entries for the sketch .ino and the generated wrapper from the same plan used by the successful build. Associate *.ino with C++ and include -x c++ where required. Generated commands must use normalized absolute paths on Windows and must be executable after the prerequisites of a successful build have been materialized.

Add a general command such as fastled --write-intellisense [DIR], retaining --write-clangd as a compatibility alias if it is already public. Generation must be deterministic and safe to repeat.

3. Generate PlatformIO-style Microsoft C/C++ configuration

Write/merge .vscode/c_cpp_properties.json with a FastLED configuration containing at least:

  • compileCommands pointing at ${workspaceFolder}/compile_commands.json;
  • sketch, FastLED, compatibility, and generated include paths in includePath and browse.path;
  • build defines;
  • forcedInclude when the compile plan uses forced headers;
  • the bundled direct compiler in compilerPath plus the required target/sysroot arguments in compilerArgs;
  • the actual cppStandard and cStandard.

Preserve unrelated user configurations and settings. Document which generated keys FastLED owns and update only those keys on refresh.

4. Install both extensions, but never run both language engines

Follow-up investigation confirmed that the two extensions can be installed together, but their language services must not be active for the same C/C++ documents:

  • Current vscode-clangd 0.6.0 explicitly detects active cpptools and warns that Microsoft IntelliSense conflicts with clangd completion and diagnostics.
  • Microsoft confirms that "C_Cpp.intelliSenseEngine": "disabled" turns off the cpptools C/C++ language service; separately disabling autocomplete and squiggles is redundant. The extension can remain installed for its non-language-service features.
  • VS Code activates extensionDependencies before the dependent extension. Declaring both language engines as hard dependencies therefore allows both to start before FastLED can arbitrate, and a missing, failed, or user-disabled dependency can prevent FastLED itself from activating.
  • The clangd extension's clangd.enable setting has default window scope and is only consulted while activating/restarting the client; changing it to false does not stop an already-running client. The extension exposes clangd.shutdown and clangd.restart, which FastLED must use during transitions.
  • C_Cpp.intelliSenseEngine has resource scope. Because clangd's enablement is window-wide and its client selects all C/C++ files, different engines per folder in one multi-root window are not safely supported. Engine selection must be one value for the whole VS Code window, while metadata generation remains per folder.
  • The VS Code clangd extension does not contain the native server. When no server is found, it offers a user-confirmed download on supported x86-64 Windows, Linux, and macOS systems. The locally installed FastLED Emscripten 4.0.19 toolchain contains clang.exe, clang++.exe, and clang-scan-deps.exe, but no clangd(.exe), so FastLED cannot currently point the extension at its own bundled server.

Use an extension pack rather than hard lifecycle dependencies for these alternative engines:

"extensionPack": [
  "ms-vscode.cpptools",
  "llvm-vs-code-extensions.vscode-clangd"
]

VS Code installs extension-pack members together with FastLED while keeping them independently manageable. This gives a fresh supported desktop profile both editor integrations without making FastLED fail when one is disabled or unavailable. If strict extensionDependencies are nevertheless chosen, both IDs can be listed, but the activation ordering, disable semantics, remote-host placement, and failure coupling above become required acceptance risks; the extension-pack design is preferred.

Add a window/workspace-scoped setting (not folder-scoped):

fastled.intelliSenseEngine = auto | clangd | cpptools | off

Behavior and transition order:

  • auto (default): choose clangd only when the clangd extension is installed and the configured clangd.path passes a bounded --version probe; otherwise select cpptools immediately. Extension presence alone is not readiness. Offer the official clangd server installer as an explicit action, and prompt before switching engines after an installation completes rather than silently changing providers mid-edit.
  • clangd: first set workspace-level C_Cpp.intelliSenseEngine=disabled, then set clangd.enable=true, run clangd.restart, and verify that the clangd client/provider becomes ready. Report a clear setup error with Install Server and Use Microsoft C/C++ actions if it does not.
  • cpptools: set clangd.enable=false, run clangd.shutdown if the extension/client is already active, then set workspace-level C_Cpp.intelliSenseEngine=default and wait for cpptools readiness.
  • off: stop managing engine selection and restore/remove only FastLED-owned setting values rather than overwriting unrelated user configuration.

Perform each transition as a serialized state change and roll back or surface an actionable failure if the selected engine does not become ready. Exactly one language engine must own completion, navigation, diagnostics, formatting, and semantic highlighting throughout managed steady state. Both extensions remain installed; they are not expected to provide C++ language features simultaneously.

A guaranteed native clangd binary would require a separate packaging decision: add clangd to every FastLED toolchain archive or implement a pinned, checksummed FastLED download with platform/architecture coverage. The VS Code manifest alone cannot guarantee the server binary.

5. Configure and refresh from the VS Code extension

On activation for every FastLED workspace folder, and after a successful compile/init, invoke the IntelliSense-generation command and apply engine arbitration. Refresh when the selected engine, build mode, FastLED checkout/ref, toolchain, or workspace folders change. Handle multi-root workspaces per folder, serialize duplicate refreshes, and expose a FastLED: Refresh IntelliSense Configuration command.

Do not report compilation success until requested metadata generation has either succeeded or produced a visible, actionable warning. Log the selected engine, generated file paths, compiler path, and refresh reason to the FastLED output channel without logging sensitive environment values.

Likely implementation files:

  • crates/fastled-cli/src/wasm_build.rs: define/expose the canonical compile plan and reuse it for production compilation.
  • crates/fastled-cli/src/clangd_config.rs (preferably renamed/generalized): render the compile database, .clangd, c_cpp_properties.json, and shared VS Code settings from the plan.
  • crates/fastled-cli/src/cli.rs, lib.rs, commands.rs, and compile_stream.rs: expose and route general IntelliSense generation while keeping compatibility.
  • vscode-plugin/package.json: declare the cpptools dependency, setting, refresh command, and test scripts.
  • vscode-plugin/src/extension.ts: detect engines, invoke configuration, manage per-folder settings/refresh, and surface failures.
  • vscode-plugin/src/test/** plus Rust tests in the modules above: unit, integration, and Extension Development Host coverage.
  • vscode-plugin/README.md, GET_STARTED.md, and root documentation: describe automatic fallback, generated files, and troubleshooting.

Acceptance criteria

  • Installing FastLED in a supported fresh desktop VS Code profile installs both ms-vscode.cpptools and llvm-vs-code-extensions.vscode-clangd through extensionPack; either engine extension can subsequently be disabled/uninstalled without disabling FastLED itself.
  • With both editor extensions installed but no usable native clangd server, opening Blink selects cpptools without hanging or losing IntelliSense, generates compile_commands.json, .vscode/c_cpp_properties.json, and the .ino C++ association, and offers an explicit clangd server installation action.
  • With a usable clangd server, auto selects clangd only after a bounded executable/readiness check. Finishing a clangd download does not silently switch the active provider during editing.
  • Explicit clangd, cpptools, and off selections are honored once per VS Code window. Multi-root workspaces generate independent metadata per FastLED folder but use one language engine across the window; conflicting folder-level requests are rejected with a clear explanation.
  • In clangd mode, workspace-level C_Cpp.intelliSenseEngine is disabled, the clangd client is running, and no cpptools IntelliSense provider or conflict warning remains. The cpptools extension may remain installed for non-language-service features.
  • In cpptools mode, clangd.enable is false, any previously running clangd client has been stopped through clangd.shutdown, cpptools is ready, and no clangd provider/process remains.
  • Switching in both directions is serialized and tested: disable/stop the losing engine before starting the winner, wait with a hard timeout, and either reach one-engine steady state or report/roll back an actionable failure.
  • Missing/unsupported clangd downloads, a bad clangd.path, disabled extensions, dependency/pack installation failure, and remote extension-host placement all fall back or fail visibly without preventing FastLED compilation commands from activating.
  • The compilation database and both editor configurations derive from the same canonical production compile plan rather than independently reconstructed flag lists.
  • After a real successful Emscripten Blink build, executing every emitted compile_commands.json entry from its declared directory exits 0, including on Windows; required Emscripten compatibility, FakeSDL, module/PCH, target, sysroot, include, and define arguments are not lost.
  • Rust tests compare emitted arguments field-for-field with the canonical compile plan, cover .ino language forcing, normalized Windows paths, deterministic output, merge preservation, and stale config refresh.
  • A real VS Code Extension Development Host test with cpptools installed and clangd absent opens Blink, waits with a hard timeout for the C/C++ engine, observes no missing-FastLED.h diagnostics, and verifies completion plus Go to Definition into the cached FastLED headers using VS Code provider commands.
  • A corresponding clangd Extension Development Host test verifies completion and Go to Definition, and clangd --check (or the configured server's equivalent check) reports no configuration errors.
  • An Extension Development Host test with both extensions installed covers first activation and both switch directions, asserts the losing language client/process is stopped, observes no clangd conflict warning, and produces no duplicate FastLED diagnostics, completions, definitions, formatting providers, or semantic highlighting.
  • Extension tests cover activation, manual refresh, refresh after compile/init, configuration changes, window-wide multi-root arbitration, idempotence, missing CLI/toolchain/server failure, disabled extension messaging, pack installation behavior, and bounded process timeouts.
  • The test matrix runs Rust unit tests, a real Emscripten compile/database replay smoke test, and VS Code extension-host tests on Windows and Linux, with at least a macOS smoke test for path/toolchain handling.
  • bash lint, soldr cargo test --workspace, the VS Code TypeScript build/tests, and the existing real WASM compile tests pass.
  • Documentation explains that both extensions are installed but only one language engine runs, the native clangd server prompt/platform limits, window-wide multi-root selection, generated/owned files, regeneration, switching, and troubleshooting.

Open questions

  • After the file-based implementation is proven, should FastLED replace generated c_cpp_properties.json with a cpptools custom configuration provider to reduce workspace-file mutation? This should be a follow-up unless file ownership or multi-root behavior proves unacceptable.
  • Should the generalized CLI command be named --write-intellisense, --write-editor-config, or remain --write-clangd with broader behavior? Whatever name is selected, preserve compatibility for the existing public flag.

Related issues

Activity

  1. zackees commented on Jul 14, 2026

    @zackees
    MemberAuthor

    Follow-up: can clangd and Microsoft C/C++ coexist?

    Installed together: yes. Active as language engines for the same C/C++ files: no.

    The current clangd extension explicitly detects active cpptools and warns that its IntelliSense conflicts with clangd completion and diagnostics. Microsoft confirms that C_Cpp.intelliSenseEngine=disabled is sufficient to turn off the cpptools language service while leaving the extension installed.

    A hard dependency on both is technically possible, but is the wrong lifecycle for alternative engines: VS Code activates extensionDependencies before FastLED, failed/disabled dependencies can block FastLED activation, and both engines can start before FastLED applies its selection. The issue now recommends:

    "extensionPack": [
      "ms-vscode.cpptools",
      "llvm-vs-code-extensions.vscode-clangd"
    ]

    This installs both with FastLED while allowing either to be independently disabled. FastLED must then serialize transitions:

    • clangd mode: disable cpptools IntelliSense first, enable/restart clangd, verify readiness;
    • cpptools mode: set clangd.enable=false, explicitly run clangd.shutdown, then enable/wait for cpptools;
    • never treat extension presence as server readiness or leave both providers active.

    Two additional constraints are now captured in the issue:

    1. clangd.enable is window-scoped, while the cpptools engine setting is resource-scoped, so engine selection must be one value per VS Code window; multi-root folders may have separate compile metadata but cannot safely mix engines.
    2. The clangd VS Code extension does not bundle the server. It prompts for a supported-platform download when clangd is missing, and the observed FastLED Emscripten 4.0.19 package contains clang/clang++ but not clangd. A guaranteed native server therefore requires a separate toolchain-packaging or pinned-download decision.

    Primary evidence: VS Code dependency activation, extension pack/dependency semantics, configuration scopes, clangd conflict/lifecycle code, clangd manifest, and Microsoft's cpptools disable confirmation.

  2. zackees commented on Jul 15, 2026

    @zackees
    MemberAuthor

    Current Windows reproduction (2026-07-15)

    A fresh Blink workspace demonstrates the remaining plugin integration gap:

    1. Install the platform-specific VSIX fastled-wasm-1.0.1-win32-x64.vsix.
    2. Confirm VS Code installed [email protected]; its bundled clangd.exe --version reports clangd version 21.1.5.
    3. Open a workspace containing only Blink.ino and right-click FastLED, CRGB, or FastLED.addLeds.

    Observed:

    • .ino is assigned the FastLED extension's arduino language ID.
    • The installed LLVM clangd extension and Microsoft C/C++ extension activate for C/C++ language IDs, not arduino.
    • The FastLED extension exposes FastLED: Show Bundled clangd Diagnostics, but does not create a language client, set clangd.path, invoke fastled --write-clangd / --write-intellisense, or register navigation providers.
    • The new workspace therefore has no compile_commands.json, .clangd, .vscode/settings.json, or .vscode/c_cpp_properties.json.

    The expected semantic-navigation commands (Go to Definition/Declaration/Implementation) are consequently absent. This is not a failed native-server installation: the native server is present and executable, but no editor engine owns the Arduino document.

    Manual acceptance test addition

    For each selected engine, start from a clean VS Code profile and a Blink workspace with no pre-existing .vscode or compilation database:

    1. Install the FastLED platform VSIX; remove clangd from PATH to prove the bundled binary is used.
    2. Open Blink.ino; wait for FastLED setup to finish, with a visible bounded failure if setup cannot complete.
    3. Verify .ino is treated as C++ for the selected engine and FastLED-owned metadata is generated/updated without overwriting unrelated user settings.
    4. Verify completion and Go to Definition on CRGB, FastLED, and FastLED.addLeds navigate into the materialized FastLED headers.
    5. Edit an unsaved function declaration in the .ino file and verify navigation/completion refreshes from the live generated C++ snapshot.
    6. Repeat in explicit clangd mode, explicit cpptools mode, and auto fallback with no usable clangd; assert exactly one language engine is active and no duplicate diagnostics/completions or clangd/cpptools conflict warning appears.
    7. Reopen the workspace and repeat after a FastLED compile or FastLED: Refresh IntelliSense Configuration.
  3. added a commit that references this issue on Jul 15, 2026
    3834043
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions