Skip to content

feat(intellisense): preprocess live .ino snapshots into canonical C++ translation units #206

Closed

Description

@zackees

Context

FastLED?s current WASM build and --write-clangd path are not Arduino-sketch complete:

  • wasm_build::sketch_ino_file() selects one .ino file and rejects sketches containing multiple .ino tabs.
  • wasm_build::create_wrapper() emits a cache wrapper that imports wasm_pch.h and #includes that raw .ino; it does not generate function prototypes, concatenate Arduino sketch tabs, or emit #line mappings.
  • clangd_config.rs creates a raw .ino compilation-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:

  1. Discover only top-level .ino files.
  2. Require/use the <sketch-directory-name>.ino tab first and append remaining .ino tabs in stable lexical order.
  3. 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.
  4. Emit a single generated C++ translation unit containing the FastLED wasm_pch.h preamble, generated prototype prelude, all sketch-tab content, and #line directives mapping diagnostics/navigation back to original .ino paths and line numbers.
  5. 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 .ino documents 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 .ino files;
  • 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.json entry for each user-visible .ino path 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 ? replace sketch_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) and extension.ts ? document collection, debouncing, cancellation, atomic refresh, and diagnostics.
  • vscode-plugin/src/test/** and Rust integration tests.

Acceptance criteria

  • Only .ino files are supported; .pde is not discovered or transformed.
  • A primary <folder>.ino plus additional top-level .ino tabs produce one deterministic C++ unit in Arduino-compatible order.
  • A forward call in an unsaved .ino receives clangd completion, diagnostics, and go-to-definition without a compile or save.
  • Cross-tab calls and definitions resolve to original .ino files, 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

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

  1. added a commit that references this issue on Jul 15, 2026
    849bbfc
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