-
-
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
Conversation
commit: @volar/eslint
@volar/jsdelivr
@volar/kit
@volar/language-core
@volar/language-server
@volar/language-service
@volar/monaco
@volar/source-map
@volar/test-utils
@volar/typescript
@volar/vscode
|
@@ -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); |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The end offset should include the whole length of the generated code.
+ (mapping.generatedLengths ?? mapping.lengths)[mapping.generatedOffsets.length - 1]; | ||
} 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 comment
The 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.
ffac5f7
to
e478c41
Compare
…ode mapped verbatim to generated code.
e478c41
to
588dcea
Compare
Since I had difficulty testing it, it took me some time to understand. Thank you for your PR! Are you planning to make the same changes to getEncodedSemanticClassifications? |
@johnsoncodehk - I haven't planned since we are not using these currently, so I would have hard time testing it. Thanks for merging the PR! |
I've started working on support of inlay hints for Angular templates and I've noticed some issues.