feat: refresh diagnostics and CodeLens when cdk.out changes - #1630
Merged
megha-narayanan merged 3 commits intoJun 16, 2026
Merged
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.
megha-narayanan
temporarily deployed
to
automation
June 15, 2026 18:31 — with
GitHub Actions
Inactive
megha-narayanan
had a problem deploying
to
integ-approval
June 15, 2026 18:31 — with
GitHub Actions
Failure
…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
temporarily deployed
to
integ-approval
June 15, 2026 19:17 — with
GitHub Actions
Inactive
megha-narayanan
marked this pull request as ready for review
June 15, 2026 19:29
rix0rrr
approved these changes
Jun 16, 2026
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
megha-narayanan
temporarily deployed
to
run-tests
June 16, 2026 12:00 — with
GitHub Actions
Inactive
…er-cdkout-watcher # Conflicts: # packages/@aws-cdk/cdk-explorer/test/lsp/server.test.ts
megha-narayanan
had a problem deploying
to
integ-approval
June 16, 2026 18:24 — with
GitHub Actions
Failure
megha-narayanan
added a commit
to megha-narayanan/aws-cdk-cli
that referenced
this pull request
Jun 22, 2026
Integrates the aws#1630 cdk.out watcher with the async assembly read path. readAssembly and buildConstructTreeAsync stay async; the watcher onChange refreshes via the async path with its rejection routed to console.error. aws#1630's watcher tests now await the async refresh (triggerWatcher settles the fire-and-forget refresh), and the sync readAssembly test doubles were made async to match the Promise-only seam.
1 task
megha-narayanan
added a commit
that referenced
this pull request
Jun 30, 2026
Adds manual synth and auto-synth-on-save to the CDK LSP. The cdk.out watcher (landed in #1630) handles all diagnostics/lens refreshes -- these commands just add new ways to produce a fresh assembly. Features: ↻ Synth now CodeLens at the top of any CDK source file (only when auto-synth is off) ▶ Enable auto-synth / ⏹ Disable auto-synth toggle Auto-synth starts disabled When auto-synth is on, saving any non-ignored file in the project triggers a synth All feedback/output goes to the Output panel, no popups Design decisions (the important ones): Concurrent synths are supressed: if a save fires during a slow synth, that save is skipped. The next save picks it up. cdk.json is read once at startup. Changing it requires an LSP restart. The toggle/synth lenses only appear on files that already have L1 resource lenses. Files with no CDK resources see nothing. Toggle state resets to disabled on LSP restart (not persisted). NOTE: One thing not in this PR (but must land before prod) is a workspace trust gate. We should verify with the user that they trust this workspace before running any synth. I may need to set up some way to preserve this between sessions. Open questions / things I need some feedback on: - Is "auto-synth" the right name? Alternatives: "synth on save", "live synth"? - Where should the toggle live? Line 0 of a CDK file works for LSP-only, but it's only visible when you're in a file with constructs. Status bar item would be better UX but needs a client extension. Is there a better alternative? - Should synth failures (app compile errors) be more visible than the Output panel? A diagnostic on the first line of the failing file, for example? - If the app has context lookups and no cached cdk.context.json, synth fails with an auth/context error. Should the error message detect this and suggest running cdk synth in terminal first? <img width="809" height="161" alt="Screenshot 2026-06-16 at 3 41 01 PM" src="https://github.com/user-attachments/assets/b542927c-0206-462f-8464-2c43f19bbe0b" /> <img width="771" height="166" alt="Screenshot 2026-06-16 at 3 41 10 PM" src="https://github.com/user-attachments/assets/52695e76-2e1d-4fc8-ada7-d1ce338512cf" /> ### 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
fossamagna
pushed a commit
to fossamagna/aws-cdk-cli
that referenced
this pull request
Jul 17, 2026
Merges the`feat/cdk-lsp' branch into `main`. The change is additive and introduces no behavior change to existing CLI commands. - New `@aws-cdk/cdk-explorer` package containing the Language Server under `lib/lsp` (server, diagnostics, CodeLens, template locator, position mapping). - Extends `@aws-cdk/cloud-assembly-api` with two parsing modules consumed by the server: `construct-tree.ts` (builds the construct tree from a cloud assembly) and `template-ranges.ts` (resolves a logical ID or property to its byte range in the template). Capabilities (folds in aws#1559, aws#1593, aws#1592, aws#1617, aws#1624, aws#1630, aws#1631, aws#1662, aws#1634, aws#1674): - Diagnostics: surfaces synth errors and policy-validation violations in the editor, mapped back to the source. - Surfaces CFN resources and adds CodeLens navigation from a construct to its template resource. - Navigation between construct source and the synthesized template in both directions. - Live refresh: diagnostics and CodeLens update when `cdk.out` changes. - Reads are constrained to the project directory, and template reads run off the LSP event loop. This PR is the server and parsing foundation. It does not add a shipped CLI command or the web explorer. ### 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 --------- Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Otavio Macedo <288203+otaviomacedo@users.noreply.github.com>
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