-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(typescript): fix inlay hints mapping for large chunks of source code mapped verbatim to generated code. #236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -936,14 +936,29 @@ function provideInlayHints(language: Language<string>, provideInlayHints: ts.Lan | |
if (serviceScript) { | ||
let start: number | undefined; | ||
let end: number | undefined; | ||
const map = language.maps.get(serviceScript.code, targetScript); | ||
const map = language.maps.get(serviceScript.code, sourceScript); | ||
for (const mapping of map.mappings) { | ||
if (isInlayHintsEnabled(mapping.data) && mapping.sourceOffsets[0] >= span.start && mapping.sourceOffsets[0] <= span.start + span.length) { | ||
start ??= mapping.generatedOffsets[0]; | ||
end ??= mapping.generatedOffsets[mapping.generatedOffsets.length - 1]; | ||
start = Math.min(start, mapping.generatedOffsets[0]); | ||
end = Math.max(end, mapping.generatedOffsets[mapping.generatedOffsets.length - 1]); | ||
if (!isInlayHintsEnabled(mapping.data)) { | ||
continue; | ||
} | ||
let mappingStart = mapping.sourceOffsets[0]; | ||
let genStart: number | undefined; | ||
let genEnd: number | undefined; | ||
if (mappingStart >= span.start && mappingStart <= span.start + span.length) { | ||
genStart = mapping.generatedOffsets[0]; | ||
genEnd = mapping.generatedOffsets[mapping.generatedOffsets.length - 1] | ||
+ (mapping.generatedLengths ?? mapping.lengths)[mapping.generatedOffsets.length - 1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The end offset should include the whole length of the generated code. |
||
} else if (mappingStart < span.start && span.start < mappingStart + mapping.lengths[0] | ||
&& mapping.sourceOffsets.length == 1 | ||
&& (!mapping.generatedLengths || mapping.generatedLengths[0] === mapping.lengths[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My Angular VirtualCode has large pieces of code copied verbatim from the original file. This condition ensures that it is correctly handled and not ignored. |
||
) { | ||
genStart = mapping.generatedOffsets[0] + span.start - mappingStart | ||
genEnd = Math.min(genStart + span.length, mapping.generatedOffsets[0] + mapping.lengths[0]) | ||
} else { | ||
continue; | ||
} | ||
start = Math.min(start ?? genStart, genStart); | ||
end = Math.max(end ?? genEnd, genEnd); | ||
} | ||
if (start === undefined || end === undefined) { | ||
start = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all maps were taken for the wrong script. It should be a source script to have correct mappings from the template to generated code