feat: template ranges + two-way template/source navigation#1624
Open
megha-narayanan wants to merge 4 commits into
Open
feat: template ranges + two-way template/source navigation#1624megha-narayanan wants to merge 4 commits into
megha-narayanan wants to merge 4 commits into
Conversation
Adds jsonc-parser@3.2.0 as a runtime dep, in preparation for computing character ranges of template resource/property blocks (PR-A). Dedupes to the jsonc-parser already resolved in the lockfile; no new version added.
…te ranges Compute character-accurate ranges of CloudFormation resource blocks in synthesized templates and use them for navigation in both directions. cloud-assembly-api: - resolveResourceRange(text, logicalId): the character range of a resource's value block, via jsonc-parser. A position-aware parse is used instead of a line scan because real templates contain literal braces and escaped quotes inside string values (for example Fn::Sub placeholders) that defeat naive brace matching. - resolveLogicalIdAtOffset(text, offset): the inverse, mapping a position in a template back to the enclosing resource's logical id. cdk-explorer LSP: - resourceTarget now returns the real resource block range (previously a zero-width cursor at the logical-id key), so the CodeLens "go to" selects the whole block. - onDefinition: go-to-definition from a synthesized template back to the construct's source, keyed by (templateFile, logicalId) since logical ids are only unique within a template. - offset and position conversions extracted to lib/lsp/positions.ts. The jsonc-parser runtime dependency is added in the preceding commit.
cloud-assembly-api now depends on jsonc-parser, so the bundled CLIs that include it (aws-cdk, cdk-assets, integ-runner) must attribute it. Regenerated via node-backpack so the build's self-mutation check passes.
…for template ranges
jsonc-parser cannot be bundled into the CLI. Its UMD entry loads its internal
modules through a parameter-shadowed require("./impl/..."), which esbuild (via
node-backpack) cannot statically trace, so the packaged cdk and cdk-assets
binaries fail their build-time sanity check with "Cannot find module
'./impl/format'". This is a known, still-open limitation
(microsoft/node-jsonc-parser#57, evanw/esbuild#1619), and node-backpack does not
expose the esbuild mainFields workaround.
Switch resolveResourceRange and resolveLogicalIdAtOffset to json-source-map, a
single-file CommonJS module that bundles cleanly and gives the same byte offsets.
The range contract and the JSON.parse(slice) oracle tests are unchanged.
json-source-map is a strict parser, so the one test that exercised lenient input
now asserts undefined.
Regenerates THIRD_PARTY_LICENSES for aws-cdk, cdk-assets, and integ-runner.
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.
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-assetsbinaries fail withCannot find module './impl/format'. Known, still-open: microsoft/node-jsonc-parser#57, 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, a single-file CommonJS module that bundles cleanly.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license