Skip to content

feat: refresh diagnostics and CodeLens when cdk.out changes#1630

Open
megha-narayanan wants to merge 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/explorer-cdkout-watcher
Open

feat: refresh diagnostics and CodeLens when cdk.out changes#1630
megha-narayanan wants to merge 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/explorer-cdkout-watcher

Conversation

@megha-narayanan

Copy link
Copy Markdown

The LSP currently reads cdk.out once at startup and never refreshes. After this PR, any
rewrite of cdk.out refreshes the editor's diagnostics and CodeLenses
automatically.

  • New lib/core/assembly-watcher.ts: a chokidar-backed watcher with a debounced
    200ms onChange, filtered to manifest.json, tree.json,
    validation-report.json. RWLock marker files (synth.lock,
    read.<pid>.<n>.lock) are excluded. Throws from onChange route through
    onError rather than leaking from the timer. Lives in lib/core/ so the web
    explorer can reuse it.
  • refreshFromAssembly is now the single fan-out for new assembly data:
    rebuild cachedIndex, publish empty diagnostics for URIs that no longer have
    violations (clearing resolved squiggles), republish current diagnostics, and
    send workspace/codeLens/refresh (gated on workspace.codeLens.refreshSupport).
  • When the validation report fails to load, last-good diagnostics are preserved,
    matching the existing contract for 'error' and 'not-found' reads.
  • Watcher started in onInitialized after the initial refresh, closed in
    onShutdown.
    Fixes #

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…nges

The LSP read cdk.out once at startup and never refreshed. This PR makes
the editor live: any time cdk.out is rewritten (an external `cdk synth`,
`cdk watch`, or a future in-process synth), diagnostics and CodeLenses
update automatically.

* New `lib/core/assembly-watcher.ts`: a chokidar-backed watcher that fires
  a debounced (200ms) onChange when `manifest.json`, `tree.json`, or
  `validation-report.json` changes. RWLock marker files (`synth.lock`,
  `read.<pid>.<n>.lock`) are filtered out. Throws from onChange are
  forwarded to onError rather than leaking from the timer. The module is
  LSP-agnostic, ready for the future web server consumer.

* `refreshFromAssembly` is now the single 'new data -> all surfaces
  update' path: it rebuilds `cachedIndex`, publishes empty arrays for
  URIs that no longer have violations (so resolved squiggles disappear
  from the editor), republishes current diagnostics, and sends
  `workspace/codeLens/refresh` (gated on the client's
  `workspace.codeLens.refreshSupport` capability).

* When the validation report fails to load, last-good diagnostics are
  preserved instead of being wiped. This matches the existing contract
  for `'error'` and `'not-found'` reads.

* Watcher lifecycle: started in `onInitialized` after the initial
  refresh, closed in `onShutdown`.

Manual synth and auto-synth-on-save are deferred to follow-up PRs; this
PR delivers freshness for any external producer.

`chokidar@^4` is now a direct cdk-explorer dep (added via projen).
It was already in the bundled graph through toolkit-lib, so this is a
promotion, not a net-new bundled dependency.
…ionsError

* Export `MANIFEST_FILE` from `cloud-assembly-api` (was private). Add
  `TREE_FILE` as a local export of `assembly-watcher.ts`. aws-cdk-lib's
  TreeMetadata hard-codes `tree.json` rather than importing a shared
  constant, so `TREE_FILE` is a consumer-side label only.

* Reader, watcher, fixtures, and tests now use the constants instead of
  repeating filename literals. Non-signal-file paths in the watcher test
  stay literal so they continue to exercise the rejection path.

* Drop `AssemblyData.violationsError` and the if-guard around the
  publish/clear loop. The producer writes `validation-report.json`
  synchronously, so a corrupt file is unreachable through normal synth
  flow. A failed load surfaces via the existing `warnings` array; the
  rare partial-write race resolves on the next watcher tick.
@megha-narayanan megha-narayanan marked this pull request as ready for review June 15, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant