Skip to content

chore: lsp branch refactor - #1593

Merged
megha-narayanan merged 4 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/cdk-lsp
Jun 4, 2026
Merged

chore: lsp branch refactor#1593
megha-narayanan merged 4 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/cdk-lsp

Conversation

@megha-narayanan

Copy link
Copy Markdown
Contributor

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

LSP server skeleton: handles initialize/shutdown lifecycle, filters
didSave notifications, triggers synth via injectable callback
Reuses `toolkit-lib`'s `createIgnoreMatcher` + `WATCH_EXCLUDE_DEFAULTS`
for file filtering (same exclusion logic as `cdk watch`)

- [ ] 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>
@megha-narayanan
megha-narayanan marked this pull request as ready for review June 3, 2026 20:07
… watchdog leak

vscode-languageserver registers an undisposable setInterval (3s ping) on
the parent process when initialize.processId is numeric. In an in-process
test harness, that PID is the Jest worker itself, so the timer never
exits and Jest hangs after tests pass. The LSP spec allows null to mean
"no parent process," which is the truth here. No production code change.
createLspHandlers builds the message handlers as plain functions over
closed-over state, with no JSON-RPC connection, streams, or framework
runtime involved. startServer becomes a thin adapter that wires those
handlers onto a real vscode-languageserver connection. Tests target
the handlers directly — no PassThrough streams, no async waits, no
vscode-languageserver watchdog timer that hangs Jest after teardown.
readonly logger?: { error(message: string): void };
}

/** Pure handler functions for LSP messages, extracted for direct unit testing. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of exposing test only logic here, take a look at what's going on in mock-child_process.ts or mock-fs.ts and see if you can move test-only logic to the test directory
https://github.com/aws/aws-cdk-cli/blob/main/packages/%40aws-cdk/cdk-assets-lib/test/mock-child_process.ts
https://github.com/aws/aws-cdk-cli/blob/main/packages/%40aws-cdk/cdk-assets-lib/test/mock-fs.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, moved test logic to test dir. i also got rid of the logger

Following the mock-fs/mock-child_process precedent in cdk-assets-lib:
production code shouldn't expose injection points whose only justified
caller is a test. Drops the test-only `logger` option, unexports
`createLspHandlers` and `LspHandlers` (now an internal `buildHandlers`),
and removes the docstrings naming "testing" as the rationale.

`onSynthRequest` stays on `LspServerOptions` as a real production
collaborator: it's the integration seam for `toolkit.synth()` at the
synth milestone, and different LSP frontends may supply different
implementations.

Test goes back to driving the real `startServer` over a `PassThrough`
stream pair via `vscode-jsonrpc`, observing log output through
`window/logMessage` notifications — the production path, not a
test-only handler dispatch.
@megha-narayanan
megha-narayanan merged commit 32fc322 into aws:feat/cdk-lsp Jun 4, 2026
7 of 8 checks passed
@megha-narayanan
megha-narayanan deleted the feat/cdk-lsp branch June 4, 2026 17:04
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