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

Neovim support

Open howarddo2208 opened this issue 1 year ago • 34 comments

Hi, This plugin is wonderful. Do you have any plans to support Neovim too?

howarddo2208 avatar Apr 18 '23 08:04 howarddo2208

Yes please! This plugin on vim/ neovim would be a blessing.

People from the community already saw it and they seem to want it badly: https://www.reddit.com/r/neovim/comments/12q7atv/pretty_errors_plugin_like_this/

edwardsavin avatar Apr 18 '23 08:04 edwardsavin

You can use https://www.npmjs.com/package/pretty-ts-errors-lsp for now to build PoC for other IDEs.

johnsoncodehk avatar Apr 18 '23 11:04 johnsoncodehk

@johnsoncodehk May I ask a question? Does pretty-ts-errors-lsp run on hover trigger?

yaegassy avatar Apr 18 '23 12:04 yaegassy

In VSCode plugin it's run on onDidChangeDiagnostics, and then get on hover trigger.

FYI: https://github.com/johnsoncodehk/pretty-ts-errors/blob/dff54f1425721beb0aa534d5a17a0ef7ffecd412/src/extension.ts#L38

johnsoncodehk avatar Apr 18 '23 12:04 johnsoncodehk

I tried it with coc.nvim. Although the appearance is a bit concerning, I confirmed that it works. (It might be a client-side issue)

sample-1

One thing that concerns me is that when I look at the trace log, it seems like the result is being output as standard output.

Trace Log
[Trace - 21:58:37.812] Sending response 'workspace/configuration - (6)'. Processing request took 1ms
Result: [
    null
]


[Trace - 21:58:37.820] Received response 'textDocument/inlayHint - (3)' in 33ms.
Result: []


<span style="color:#f96363;">⚠ Error</span><span style="color:#5f5f5f;">
(TS2322) 
<a title="See detailed explanation" href="https://typescript.tv/errors/#TS2322">
  <span class="codicon codicon-link-external">
  </span>
</a>  | 
<a title="See translation" href="https://ts-error-translator.vercel.app/?error=CoTwDgpgBA5AdgVwLYCMICcZQJYGcpwD2ALlAIa67YDmcZKANtMYVMeNDLsetnNTAB0QA">
  <span class="codicon codicon-globe">
  </span>
</a>
</span>
<span>

<span>
Type </span>
<span class="codicon codicon-none" style="background-color:var(--vscode-textCodeBlock-background);">

  ```type
   number 
is not assignable to type
 string 
[Trace - 21:58:37.828] Received notification 'textDocument/publishDiagnostics'. Params: { // ...snip } ```

yaegassy avatar Apr 18 '23 13:04 yaegassy

sample-1

Could you provide the configuration for using with coc.nvim ? I use the default neovim lsp and I want to port a version

cherryramatisdev avatar Apr 18 '23 13:04 cherryramatisdev

It should be entirely just logic in the language client, I'm not sure why it would affect the LSP trace.

johnsoncodehk avatar Apr 18 '23 13:04 johnsoncodehk

@cherryramatisdev I think johnsoncodehk's tweet would be helpful as a reference.

https://twitter.com/johnsoncodehk/status/1648228278149455872

yaegassy avatar Apr 18 '23 13:04 yaegassy

@yaegassy Are you using @volar-plugins/pretty-ts-errors or building a client plugin based on pretty-ts-errors-lsp?

johnsoncodehk avatar Apr 18 '23 13:04 johnsoncodehk

@johnsoncodehk I tried with @volar-plugins/pretty-ts-errors.

yaegassy avatar Apr 18 '23 13:04 yaegassy

For @volar-plugins/pretty-ts-errors, in VSCode it also needs to set isTrusted and supportHtml in the language client middleware. I'm not sure if coc supports it. https://github.com/volarjs/volar.js/blob/5ae44d90936045b92ad9debcfb9ae952bb311fb8/packages/vscode/src/index.ts#L27-L28

johnsoncodehk avatar Apr 18 '23 13:04 johnsoncodehk

@yaegassy please update @volar-plugins/pretty-ts-errors to 2.0.0-alpha.23-patch.2, it should fixed the logging issue.

johnsoncodehk avatar Apr 18 '23 13:04 johnsoncodehk

@johnsoncodehk I checked that the issue with the log has been resolved!

Just one more thing, please allow me to confirm for the sake of being thorough. This is regarding the Markdown content of the hover response. Is there any additional processing required for "quotes" or anything else?

[Trace - 23:01:20.856] Received response 'textDocument/hover - (14)' in 4ms.
Result: {
    "contents": {
        "kind": "markdown",
        "value": "```typescript\n(property) name: string\n```\n\n---\n\n<span style=\"color:#f96363;\">⚠ Error</span><span style=\"color:#5f5f5f;\">\n(TS2322) \n<a title=\"See detailed explanation\" href=\"https://typescript.tv/errors/#TS2322\">\n  <span class=\"codicon codicon-link-external\">\n  </span>\n</a>  | \n<a title=\"See translation\" href=\"https://ts-error-translator.vercel.app/?error=CoTwDgpgBA5AdgVwLYCMICcZQJYGcpwD2ALlAIa67YDmcZKANtMYVMeNDLsetnNTAB0QA\">\n  <span class=\"codicon codicon-globe\">\n  </span>\n</a>\n</span>\n<span>\n\n<span>\nType </span>\n<span class=\"codicon codicon-none\" style=\"background-color:var(--vscode-textCodeBlock-background);\">\n\n  ```type\n   number \n  ```\n\n</span>\n<span> is not assignable to type </span>\n<span class=\"codicon codicon-none\" style=\"background-color:var(--vscode-textCodeBlock-background);\">\n\n  ```type\n   string \n  ```\n\n</span>\n<span>\n</span>"
    },
    "range": {
        "start": {
            "line": 4,
            "character": 15
        },
        "end": {
            "line": 4,
            "character": 19
        }
    }
}

yaegassy avatar Apr 18 '23 14:04 yaegassy

I tried it on VSCode, but since the response was the same, I assume the issue is on the client side that I'm using. I resolved it myself. 🙇

yaegassy avatar Apr 18 '23 14:04 yaegassy

Bump. Would love this in NeoVim 🙏🏻

g1sbi avatar Apr 27 '23 18:04 g1sbi

I started the migration to a monorepo and now I'm exporting a formatting function that can be customizable. I would be happy to test it and try to make it work with Neovim. Are you willing to help via Discord? @yaegassy @cherryramatisdev

yoavbls avatar Apr 29 '23 18:04 yoavbls

Don't know if you still need help with this @yoavbls but I'm available!

olrtg avatar Jul 05 '23 18:07 olrtg

Hi @yoavbls. Do you have any thoughts or advice on how a neovim plugin should be structured?

I briefly experimented trying to create one a few months back, but wasn't sure how to nicely render the final text produced by pretty-ts-errors. Do you think it's feasible to have pretty-ts-errors output in a markdown format? Then we can easily render it in neovim (or any other editor that supports markdown) with all that markdown has to offer (syntax highlighting, concealed hyperlinks, etc)

thenbe avatar Aug 13 '23 08:08 thenbe

This issue inspired me to build https://github.com/piersolenski/wtf.nvim - which uses the power of AI to both better explain Typescript errors and give you custom tailored solutions. The best part is it actually works with any language with LSP support, and any level of diagnostic message. For those who don't want to use AI, it also allows you to open a search for diagnostic messages in your favourite resources such as Google, Stack Overflow, Github Issues etc - and I plan to support other sources soon!

piersolenski avatar Aug 25 '23 14:08 piersolenski

Bump!

abdelrahman-essawy avatar Aug 27 '23 18:08 abdelrahman-essawy

How do we go about adding this to volar with lsp-config?

        volar = {
          filetypes = { 'javascript', 'typescript', 'vue' }, -- enable takeover mode for js files - https://github.com/johnsoncodehk/volar/discussions/471
        },

9mm avatar Sep 15 '23 02:09 9mm

I'm still looking for some help here. Is most of the TypeScript developers in Neovim is working with coc-volar of @yaegassy? If so I'll just work on creating an official service and guide for volar.js

yoavbls avatar Sep 18 '23 23:09 yoavbls

I suspect that most TS devs using neovim are using the built-in LSP with typescript.nvim or typescript-tools.nvim, but I don't know for sure.

mmirus avatar Sep 19 '23 00:09 mmirus

I'm still looking for some help here. Is most of the TypeScript developers in Neovim is working with coc-volar of @yaegassy? If so I'll just work on creating an official service and guide for volar.js

maybe most of user just use tsserver with built-in lsp

nfwyst avatar Oct 01 '23 17:10 nfwyst

Personally, I'm using COC atm. Want to refactor my setup but that's besides the point.

Otard95 avatar Oct 02 '23 05:10 Otard95

Personally, I'm using COC atm. Want to refactor my setup but that's besides the point.

if you want, you can copy my config here: https://github.com/nfwyst/perfect-neovim-config/blob/main/lua/plugins/lsp/config.lua, im using lazy.nvim, its very fast!

nfwyst avatar Oct 03 '23 03:10 nfwyst

if you want, you can copy my config

I like the structure. I'll probably take some inspiration from this! Thanks!

Otard95 avatar Oct 03 '23 06:10 Otard95

Hey, I am actually attempting to achieve similar results in Neovim with my home-made-home-baked plugin here. It's not on par features wise with this yet, and does not use the same LSP under the hood, because error message formatted into html is no of good use to us, neovim plebs, but it attempts to manually parse some stuff. So, feel free to give it a go, if you want. https://github.com/OlegGulevskyy/better-ts-errors.nvim

OlegGulevskyy avatar Dec 03 '23 11:12 OlegGulevskyy

+1, I hope this comes to something like LazyVim, I didn't get anything from above working yet

aindriu80 avatar Jan 04 '24 10:01 aindriu80

I have been using this is vs code before moving to neovim and I dearly miss it would love this to come to neovim and I will be glad to help

adex-codez avatar Jan 26 '24 10:01 adex-codez