feat: refresh diagnostics and CodeLens when cdk.out changes#1630
Open
megha-narayanan wants to merge 2 commits into
Open
feat: refresh diagnostics and CodeLens when cdk.out changes#1630megha-narayanan wants to merge 2 commits into
megha-narayanan wants to merge 2 commits into
Conversation
…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.
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.
The LSP currently reads
cdk.outonce at startup and never refreshes. After this PR, anyrewrite of
cdk.outrefreshes the editor's diagnostics and CodeLensesautomatically.
lib/core/assembly-watcher.ts: a chokidar-backed watcher with a debounced200ms
onChange, filtered tomanifest.json,tree.json,validation-report.json. RWLock marker files (synth.lock,read.<pid>.<n>.lock) are excluded. Throws fromonChangeroute throughonErrorrather than leaking from the timer. Lives inlib/core/so the webexplorer can reuse it.
refreshFromAssemblyis now the single fan-out for new assembly data:rebuild
cachedIndex, publish empty diagnostics for URIs that no longer haveviolations (clearing resolved squiggles), republish current diagnostics, and
send
workspace/codeLens/refresh(gated onworkspace.codeLens.refreshSupport).matching the existing contract for
'error'and'not-found'reads.onInitializedafter the initial refresh, closed inonShutdown.Fixes #
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license