Skip to content

Why in plugin mode, the virtual code is offset by the size of the original file? #188

Answered by johnsoncodehk
piotrtomiak asked this question in Q&A
Discussion options

You must be logged in to vote

Due to the fact that the TS LanguageService API returns offsets instead of line/column positions, tsserver needs to convert the offsets to line/column positions. The purpose of adding offsets is to allow tsserver to correctly convert offsets to line/column positions.

Consider the following source code and virtual code.

Source code:

<script setup>
// @ts-expect-error
let foo: string = 1;
//  ^^^ 39~42
</script>

Virtual code without offset:

export default defineComponent(() => {
// @ts-expect-error
let foo: string = 1;
//  ^^^ 64~67
})

Virtual code with offset:

              
                   
                   
            
        
export default defineComponent(() => {
// @ts-expect-e…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@piotrtomiak
Comment options

Answer selected by piotrtomiak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants