feat: integrate lsp feature branch#1681
Open
megha-narayanan wants to merge 15 commits into
Open
Conversation
Basic scaffolding for new packages to be implemented: a core functionality library, the lsp server, and 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
Refactor: put LSP skeleton in a unique branch from web explorer - [ ] 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 --------- 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 --------- 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>
- Adds an assembly reader that joins `cdk.out/`'s `tree.json` with each stack's manifest metadata into a `ConstructNode` tree carrying `logicalId`, CFN type, and source location. - LSP publishes CDK validation violations as `Diagnostic`s anchored to the construct's TypeScript source line, with rule-level severity. - LSP serves `CodeLens` entries above each construct creation site summarising the CFN resources it produces. - Source resolution covers `.ts` and `.js` (with sibling `.js.map`); non-TS apps degrade gracefully (no crash, no source-linked features). 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
Builds on #1592, which surfaced display-only CodeLens entries for the CFN resources each construct produces. This PR makes them **clickable**. Selecting a lens jumps to the resource's definition in the synthesized CloudFormation template. Features: - **Clickable navigation** — each lens carries an `openResource` command that opens the resource's template file at its logical-ID line. - **Multi-resource picker** — constructs producing several resources show a QuickPick; single-resource constructs open directly. - **Positional `templateFile` resolution (cloud-assembly-api)** — `buildConstructTree` threads the owning template through the tree, switching at NestedStack boundaries. - **Clearer titles** — `Creates AWS::S3::Bucket`, or `Creates 3 resources: AWS::S3::Bucket, AWS::S3::BucketPolicy, AWS::KMS::Key`. ### 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>
- Computes character ranges for CloudFormation resource blocks in
synthesized templates and uses them for navigation in both directions:
-
- CodeLens "go to" now selects the whole resource block (was a
zero-width cursor).
- New go-to-definition from a synthesized template back to the
construct's source.
A note on the JSON parser dependency Computing character ranges needs a
position-aware JSON parser, since JSON.parse discards offsets. The
natural choice is jsonc-parser (what the VS Code JSON language service
uses). We could not use it here: its UMD entry loads internal modules
through a parameter-shadowed require("./impl/...") that esbuild (used by
node-backpack to bundle the CLI) cannot statically trace, so the bundled
`cdk/cdk-assets` binaries fail with `Cannot find module
'./impl/format'`. Known, still-open:
[microsoft/node-jsonc-parser#57](microsoft/node-jsonc-parser#57),
[evanw/esbuild#1619](evanw/esbuild#1619). Its
ESM build bundles fine, but the esbuild mainFields workaround isn't
exposed by node-backpack, and importing the ESM build directly breaks
our CommonJS tests; marking it external isn't appropriate for a
self-contained CLI. So we use
[json-source-map](https://www.npmjs.com/package/json-source-map), a
single-file CommonJS module that bundles cleanly.
### 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
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
The LSP followed source/template paths from the cloud assembly (stack-trace frames, source maps, template paths) with only an extension allow-list. If cdk.out is tampered with, a crafted path like `../../../etc/passwd.js` could be read or surfaced as a nav target. Adds a symlink-aware `isWithinRoot` and gates every read: source paths against the project dir, `templateFile` against the assembly dir. Out-of-root paths are dropped as not-navigable (same as non-TS apps). No change for valid assemblies. 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
Convert the two synchronous template reads on the LSP request paths (onDefinition and the CodeLens provider) to fs.promises, continuing the async direction from #1631. resourceTarget, codeLensesForFile, and commandFor are now async and read sequentially, so the number of concurrent reads never grows with app size. The LspHandlers interface widens onCodeLens and onDefinition to return Promises; the connection wiring passes the Promise through unchanged. readAssembly and the source-map reads stay synchronous: they run at startup and on watch events, not per request, and convert-source-map takes a synchronous reader. 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
# Conflicts: # packages/@aws-cdk/integ-runner/THIRD_PARTY_LICENSES # packages/aws-cdk/THIRD_PARTY_LICENSES # packages/cdk-assets/THIRD_PARTY_LICENSES # yarn.lock
Contributor
Dependency ReviewThe following issues were found:
License Issuespackages/@aws-cdk/cdk-explorer/package.json
packages/@aws-cdk/cloud-assembly-api/package.json
yarn.lock
OpenSSF ScorecardScorecard details
Scanned Files
|
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1681 +/- ##
==========================================
+ Coverage 89.37% 89.59% +0.22%
==========================================
Files 77 77
Lines 11716 11711 -5
Branches 1625 1643 +18
==========================================
+ Hits 10471 10493 +22
+ Misses 1214 1189 -25
+ Partials 31 29 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Contributor
|
Total lines changed 4129 is greater than 1000. Please consider breaking this PR down. |
Setting JSII_HOST_STACK_TRACES=1 on the synth subprocess makes jsii forward the host-language frames, so resolveFrames finds the .py/.java source. ### 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
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.
Merges the
feat/cdk-lsp' branch intomain`. The change is additive and introduces no behavior change to existing CLI commands.@aws-cdk/cdk-explorerpackage containing the Language Server underlib/lsp(server, diagnostics, CodeLens, template locator, position mapping).@aws-cdk/cloud-assembly-apiwith two parsing modules consumed by the server:construct-tree.ts(builds the construct tree from a cloud assembly) andtemplate-ranges.ts(resolves a logical ID or property to its byte range in the template).Capabilities (folds in #1559, #1593, #1592, #1617, #1624, #1630, #1631, #1662, #1634, #1674):
cdk.outchanges.This PR is the server and parsing foundation. It does not add a shipped CLI command or the web explorer.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license