yoavbls / pretty-ts-errors

🔵 Make TypeScript errors prettier and human-readable in VSCode 🎀
https://marketplace.visualstudio.com/items?itemName=yoavbls.pretty-ts-errors
MIT License
13.14k stars 89 forks source link

Casing issue in uri.path between formatted diagnostics and hoverProvider #100

Closed kevinramharak closed 3 months ago

kevinramharak commented 4 months ago

Describe the bug I noticed that I did not get any prettified errors when working from a .vue file.

I setup a basic snippet like:

<script setup lang="ts">
import { RouterView } from 'vue-router';

const x = [1, 2, 3, '4'];

function y(param: number[]) {

}

y(x); 

</script>
<template>
    <RouterView />
</template>

And per screenshot the highlighter result: image

Expected behavior I expected to see a prettified error message as vue support is implemented.

Cause I cloned the repo and ran it with the debugger and found that this issue is caused by the following:

https://github.com/yoavbls/pretty-ts-errors/blob/b388ac534847a809d78c49211b023b2fb39c33f8/src/extension.ts#L72

On this line the value of uri.path is: '/c:/Users/kevin/Documents/Projects/phavuer-playground/src/App.vue'

When in the hoverProvider.ts: https://github.com/yoavbls/pretty-ts-errors/blob/b388ac534847a809d78c49211b023b2fb39c33f8/src/provider/hoverProvider.ts#L6-L10

The value of document.uri.path is '/C:/Users/kevin/Documents/Projects/phavuer-playground/src/App.vue'.

Notice the casing difference of the C drive:

- '/c:/Users/kevin/Documents/Projects/phavuer-playground/src/App.vue'
+ '/C:/Users/kevin/Documents/Projects/phavuer-playground/src/App.vue'

This causes the hoverProvider to think there are no stored items to show, and thus show no results.

Fix VS Code seems to use this implementation for the Uri class.

Maybe use fsPath instead as it states:

/**
* Returns a string representing the corresponding file system path of this URI.
* Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the
* platform specific path separator.
*
* * Will *not* validate the path for invalid characters and semantics.
* * Will *not* look at the scheme of this URI.
* * The result shall *not* be used for display purposes but for accessing a file on disk.
*
*
* The *difference* to `URI#path` is the use of the platform specific separator and the handling
* of UNC paths. See the below sample of a file-uri with an authority (UNC path).
*/
yoavbls commented 3 months ago

Thank you for the detailed issue! I think the main reason it didn't work is that In the new official extension of Vue VSCode plugin, Hybrid mode is enabled by default, which means that a TypeScript LSP Plugin publishes the diagnostics as ts-plugin instead of ts. I fixed it in #103, published in v0.5.4. I also moved to fsPath. It is better, and I wasn't aware of that. Thank you!

sentience commented 3 months ago

@yoavbls Looks like v0.5.4 still needs to be merged into main (or perhaps you just haven't pushed your changes to main)?