Skip to content

feat: support source tracing for java and python#1674

Open
megha-narayanan wants to merge 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/explorer-polyglot-source
Open

feat: support source tracing for java and python#1674
megha-narayanan wants to merge 2 commits into
aws:feat/cdk-lspfrom
megha-narayanan:feat/explorer-polyglot-source

Conversation

@megha-narayanan

@megha-narayanan megha-narayanan commented Jun 25, 2026

Copy link
Copy Markdown

Add utilities to source resolver to parse jsii host-language (Python/Java) creation-stack frames, and drop the TypeScript-only diagnostics gate. Go-to-definition (source → template, and reverse) and policy-violation diagnostics now work for Python/Java apps, not just TypeScript.

Requires synthing with JSII_HOST_STACK_TRACES=1 (opt-in; jsii 1.137+ / aws-cdk-lib 2.260+). Auto-enabling it for LSP-triggered synth is a follow-up.

Example:
Screenshot 2026-06-25 at 1 30 10 PM

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

Parse jsii host-language (Python/Java) creation-stack frames in the source resolver and remove the TypeScript-only diagnostics gate, so go-to-definition and policy violations work for non-TypeScript CDK apps synthed with JSII_HOST_STACK_TRACES=1. Verified end to end against jsii 1.137.0 and aws-cdk-lib 2.260.0.
@megha-narayanan megha-narayanan marked this pull request as ready for review June 25, 2026 17:36
@github-actions github-actions Bot added the p2 label Jun 25, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team June 25, 2026 17:48
return SUPPORTED_SOURCE_EXTENSIONS.some((ext) => file.endsWith(ext));
// Host frame columns are 0-indexed (0 = unavailable); SourceLocation is 1-based.
function normalizeHostFrame(loc: SourceLocation): SourceLocation {
return { file: loc.file, line: loc.line, column: loc.column + 1 };

@otaviomacedo otaviomacedo Jun 26, 2026

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.

Shouldn't it be:

Suggested change
return { file: loc.file, line: loc.line, column: loc.column + 1 };
return { file: loc.file, line: loc.line, column: Math.max(1, loc.column) };

If the column is greater than zero, we want to preserve it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As of right now at least, jsii's Python runtime always hardcodes the column to 0 as an "unavailable" sentinel and the kernel omits column 0 from the frame string, so every real Python/Java frame arrives with no column. So this is all code to support in the future if columns are sent in the frames. My logic here was to treat host columns as 0-based (which is Python's col_offset convention), so + 1 converts a 0-based column for the SourceLocation which is 1-based (at least the way I have done it now). Let me know if you still think this needs a change.

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