pretty-ts-errors icon indicating copy to clipboard operation
pretty-ts-errors copied to clipboard

Some TypeScript diagnostics are not handled

Open thjxs opened this issue 1 year ago • 6 comments

Describe the bug Moving the cursor around the errors may reveal that certain diagnostics are not being processed.

Expected behavior Handle all diagnostics.

Screenshots

https://github.com/user-attachments/assets/357fa273-2cb2-4aaf-87f3-640c401758dc

thjxs avatar Oct 20 '24 07:10 thjxs

Thank you for opening an issue, It seems like something changed in VSCode behavior recently and the original diagnostics hover takes ±1 character from the original range of the curly braces. I have no idea why it's like that and why it's not happening for pretty-ts-errors diagnostics since it copies the same range object from the original diagnostic. any help could be helpful 🙏🏼

yoavbls avatar Nov 23 '24 19:11 yoavbls

@yoavbls I suspect that could be caused by the many regex that use {0, }. An empty space is truthy with that type of regex.

jdegand avatar Sep 03 '25 14:09 jdegand

@jdegand @yoavbls This has to do with the hoverProvider at https://github.com/yoavbls/pretty-ts-errors/blob/e041cfd4ffb6ad8d252e554a10a0ed757e8b1992/src/provider/hoverProvider.ts#L12-L14

If the user hovers at the whitespace before it, TS triggers to show its diagnostic, even if it's not actually in range. We could try and match this behavior, but then it would make sense to peek at the source code if we can, to figure out what their behaviour is.

kevinramharak avatar Oct 09 '25 14:10 kevinramharak

Looking further into this, I think this is the source code as it iss part of the vscode codebase itself.

It's not easy to copy, as it actually calls the TS language server with a quickinfo request for the current hover position, then if there is a response, it will format whatever the language server has send to a markdown format. As far as I can tell it does not differ between a hover position having diagnostics or not, that part seems to happen on the language server side.

kevinramharak avatar Oct 09 '25 16:10 kevinramharak

@kevinramharak I searched the VSCode issues and didn't find any pointing out this specific behavior. There are numerous issues related to unexpected whitespace removal and maybe they decided to preserve any whitespace. The range, const range = typeConverters.Range.fromTextSpan(response.body), uses TextSpan, which doesn't automatically exclude whitespace.

jdegand avatar Oct 09 '25 17:10 jdegand

It took some digging but I think the cause is this getTouchingPropertyName in https://github.com/microsoft/TypeScript/blob/d8aafb3197ebecd7faf919eaa39e77c5805cbff8/src/services/services.ts#L2282C22-L2282C45.

This enables the editor/quickinfo to give relevant hover information even if you are not directly hovering over the error range itself. I tried it with a few different cases, it also allows for things like hovering over the big whitespace part of the end of a line, and still get hover information of what you probably care about. Its a pretty smart UX feature, but I don't know how we can detect this ourselves. I thought about writing a Language Server Plugin but that seems limited to only what the language server sends back. Maybe using the middleware feature of Language Service Request Forwarding we can spy on these hover requests, and see when the typescript language features extension will show a diagnostic and use it to trigger our own.

kevinramharak avatar Oct 19 '25 11:10 kevinramharak