Skip to content

fix: read templates off the LSP event loop - #1662

Merged
megha-narayanan merged 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/cdk-lsp-async-io
Jun 23, 2026
Merged

fix: read templates off the LSP event loop#1662
megha-narayanan merged 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/cdk-lsp-async-io

Conversation

@megha-narayanan

Copy link
Copy Markdown
Contributor

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

Convert the two synchronous template reads on the LSP request paths (onDefinition and the CodeLens provider) to fs.promises, continuing the async direction from aws#1631. A blocking read stalled the single LSP event loop and delayed every other editor request.

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.
@github-actions github-actions Bot added the p2 label Jun 22, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team June 22, 2026 19:07
@megha-narayanan
megha-narayanan marked this pull request as ready for review June 22, 2026 20:46
…p-async-io

# Conflicts:
#	packages/@aws-cdk/cdk-explorer/test/lsp/server.test.ts
@megha-narayanan
megha-narayanan merged commit 6af9428 into aws:feat/cdk-lsp Jun 23, 2026
7 of 8 checks passed
@megha-narayanan
megha-narayanan deleted the feat/cdk-lsp-async-io branch June 23, 2026 14:12
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>
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.

2 participants