feat: support source tracing for java and python#1674
Open
megha-narayanan wants to merge 2 commits into
Open
Conversation
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.
| 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 }; |
Contributor
There was a problem hiding this comment.
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.
Author
There was a problem hiding this comment.
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.
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.
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:

Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license