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
|
| 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.
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.
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.
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.