Repository navigation
Description
Context
FastLED?s current WASM build and --write-clangd path are not Arduino-sketch complete:
wasm_build::sketch_ino_file()selects one.inofile and rejects sketches containing multiple.inotabs.wasm_build::create_wrapper()emits a cache wrapper that importswasm_pch.hand#includes that raw.ino; it does not generate function prototypes, concatenate Arduino sketch tabs, or emit#linemappings.clangd_config.rscreates a raw.inocompilation-database entry with-x c++, but a raw sketch can contain valid Arduino forward calls that are invalid C++ until prototypes are generated.- VS Code sends unsaved document text to clangd, but the current metadata path only reads files from disk. A build or saved file must not be required before completion works.
Arduino sketch semantics require only top-level .ino files: the file matching the sketch directory is first, other .ino files follow alphabetically, prototypes are injected, and generated C++ uses #line directives to preserve source locations. FastLED supports .ino only for this work; .pde is out of scope.
Proposal
Introduce one Rust-owned, deterministic SketchPreprocessor shared by the real WASM build and editor integration.
Canonical preprocessing
Given a sketch root and a versioned source-content provider:
- Discover only top-level
.inofiles. - Require/use the
<sketch-directory-name>.inotab first and append remaining.inotabs in stable lexical order. - Generate correct C++ declarations for functions that need forward declarations. Do not implement this with a regex-only parser; support templates, attributes, qualifiers, namespaces, function pointers, comments, strings, and manually provided prototypes safely.
- Emit a single generated C++ translation unit containing the FastLED
wasm_pch.hpreamble, generated prototype prelude, all sketch-tab content, and#linedirectives mapping diagnostics/navigation back to original.inopaths and line numbers. - Produce a stable manifest containing source-file list, document versions/content hashes, generation id, and generated-file hashes.
The real build must compile this same canonical generated translation unit, not a second wrapper implementation.
Live editor snapshots
Add a local, versioned request protocol for the VS Code extension to send open-document text to the FastLED CLI/preprocessor. The extension must:
- collect unsaved text from open
.inodocuments and disk text for unopened tabs; - debounce edits (roughly 250?500 ms), cancel obsolete requests, and prevent an older generation from replacing a newer one;
- atomically write only ignored cache state under
<sketch>/.fastled/intellisense/; - never rewrite, save, rename, or otherwise modify user
.inofiles; - preserve the last known-good generated prototype prelude if a transient half-typed edit cannot be preprocessed;
- surface actionable preprocessing failures without disabling FastLED compile commands.
Language-server integration
Generate both views from the same preprocess result:
- A canonical generated C++ entry for background indexing and cross-tab symbol discovery.
- A
compile_commands.jsonentry for each user-visible.inopath using-x c++, the exact FastLED/WASM compile plan, and a forced include of the generated prototype prelude.
This lets clangd continue parsing VS Code?s live .ino buffer while it has the declarations and flags needed for completion. Do not restart clangd for every keystroke. Restart/reload only when CDB topology, toolchain, build mode, or compile flags change; ordinary snapshot/header updates must remain incremental.
Generate equivalent engine-neutral metadata for cpptools, including the same forced include, so #203 can select either language engine without different sketch semantics.
Likely touch points
crates/fastled-cli/src/sketch_preprocessor.rs? canonical discovery, snapshot, prototype, line-map, and manifest model.crates/fastled-cli/src/wasm_build.rs? replacesketch_ino_file()/create_wrapper()with canonical preprocessor output.crates/fastled-cli/src/clangd_config.rs? render CDB and editor metadata from preprocess output plus the canonical compile plan.crates/fastled-cli/src/cli.rs,lib.rs,commands.rs? expose the versioned editor snapshot request.vscode-plugin/src/intellisense.ts(new) andextension.ts? document collection, debouncing, cancellation, atomic refresh, and diagnostics.vscode-plugin/src/test/**and Rust integration tests.
Acceptance criteria
- Only
.inofiles are supported;.pdeis not discovered or transformed. - A primary
<folder>.inoplus additional top-level.inotabs produce one deterministic C++ unit in Arduino-compatible order. - A forward call in an unsaved
.inoreceives clangd completion, diagnostics, and go-to-definition without a compile or save. - Cross-tab calls and definitions resolve to original
.inofiles, with correct original line numbers. - The actual WASM build and editor output use the exact same preprocessing implementation and source ordering.
- Generated prototype handling covers ordinary functions and safely rejects/requires manual declarations for unsupported pathological forms; it never silently emits an incorrect declaration.
- Rapid document changes cannot publish stale cache output.
- Invalid transient editor text retains the last-known-good prelude while still showing the user?s current syntax diagnostics.
- Cache output is atomic, ignored by git, disposable, and never changes a user source file.
- CDB entries contain absolute normalized paths,
-x c++, required FastLED/WASM flags, and the generated prototype forced-include. - Rust tests plus Extension Development Host tests cover unsaved edits, forward references, multi-tab ordering, diagnostic line mapping, rename/delete, cancellation, and cpptools/clangd metadata equivalence.
Related issues
- feat(vscode): provide verified clangd and Microsoft C/C++ IntelliSense for WASM sketches #203 ? IntelliSense metadata, extension installation, and language-engine arbitration. This issue provides the canonical preprocessed source model it consumes.
- feat(vscode): bundle verified native clangd in platform-specific VSIX packages #204 ? bundled native clangd support, now complete.
Implementation provenance and fbuild dependency plan
FastLED/fbuild already provides a Rust .ino processor in crates/fbuild-build-engine/src/source_scanner.rs. It uses a tree-sitter C++ parser to order sketch tabs and create function prototypes, so this work must not reimplement that logic from scratch.
Initial implementation: copy/adapt fbuild's processor and its focused tests into fastled-wasm, then extend it for this issue's live-content provider, atomic editor snapshots, canonical FastLED WASM preamble, and per-tab #line mappings. Keep the integration behind a narrow adapter and preserve compatible behavior; contribute generic preprocessing improvements upstream instead of letting the copies drift.
This copied implementation is transitional. The planned end state is to make fbuild a pinned dependency of fastled-wasm and replace the local copy with its reusable preprocessor API once fbuild exposes and versions that API cleanly. Until then, pin this implementation provenance to fbuild commit 1e75ccf5a4ca922b4d922a6da286b965fac8832d in code comments/tests.
Activity
fix(intellisense): preserve extern C linkage
feat(intellisense): preprocess live Arduino sketches (#207)