Inspired by https://github.com/yoavbls/pretty-ts-errors. This CoC extension is a port of the original extension to work with CoC.
Based on https://github.com/hexh250786313/pretty-ts-errors-markdown.
20240704_120525.mp4
-
Show TypeScript error messages in a more readable format.
-
You can choose to use
doHover
or diagnostic floating window to display error message by optionpretty-ts-errors.mode
. -
There are two ways to highlight code blocks, one is to use the highlight group
PrettyTsErrorType
to highlight a single color, and the other is to use ts syntax highlight.※ Personally, I prefer to use
prettytserr
to highlight a single color, because it is more readable and does not affect the original code.
Make sure you have coc.nvim
and coc-tsserver
installed.
And make sure your coc.nvim
includes the pr https://github.com/neoclide/coc.nvim/commit/9c079ad79d66d4ede7886cc4094a822352559502 which gives diagnostic floating window highlight.
Then run the following command:
:CocInstall coc-pretty-ts-errors
CocMarkdownCode
is for inline code.CocMarkdownLink
is for file link.PrettyTsErrorType
is for the code block if you chooseprettytserr
inpretty-ts-errors.codeBlockHighlightType
.PrettyTsErrorType
defaults link toCocMarkdownCode
.
![2024-07-09_10-48](https://private-user-images.githubusercontent.com/26080416/346840310-22224233-eab2-4de4-ba84-9b5da0e97f34.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NjgyMTgsIm5iZiI6MTczOTU2NzkxOCwicGF0aCI6Ii8yNjA4MDQxNi8zNDY4NDAzMTAtMjIyMjQyMzMtZWFiMi00ZGU0LWJhODQtOWI1ZGEwZTk3ZjM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDIxMTgzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM0YmNlMGM1ZWY3ZDE2MmRiNDdiYTYzZDcwZjUyMDk4ZTY2YmNkYTRlYjU1YjA0ODY2OThjYjEzN2IxY2EzYWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6sqZwT41lcUpqqFGDvfMOAm20lZsbxCAvYwPPE4imrA)
Here are the available configuration options for coc-pretty-ts-errors:
pretty-ts-errors.enable
: (Boolean, default:true
) Enable or disable the coc-pretty-ts-errors extension.pretty-ts-errors.showLink
: (Boolean, default:false
) Show ref links in error message.pretty-ts-errors.mode
: (0 | 1 | 2, default:1
) Display mode of the error message.pretty-ts-errors.codeBlockHighlightType
: ("prettytserr" | "typescript", default:"prettytserr"
) The way to highlight code block.pretty-ts-errors.serverName
: (String, default:"tsserver"
) The name of the language server. Set it to 'tsserver' if youse coc-tsserver. Otherwise, set it to your customized typescript language server name.pretty-ts-errors.experimental.filterOriginalTsErrors
: (Boolean, default:false
) (Experimental) Filter original (and ugly) ts errors in the diagnostic floating window.
-
Q: When to use
serverName
-
A: Examples:
-
When using coc-tsserver ,
serverName
is"tsserver"
-
When using a customized typescript
"languageserver"
, you need to modifyserverName
to the corresponding values, such as typescript-language-server// coc-settings.json "pretty-ts-errors.serverName": "my-tsserver", ~~~~~~~~~~~~~ Your customized typescript language server name. "languageserver": { "my-tsserver": { ~~~~~~~~~~~~~ `serverName` is from here. "enable": true, "command": "typescript-language-server", "args": ["--stdio"], ... ...other options } }
-
Some common typescript language server names:
- coc-tsserver:
- repository: https://github.com/neoclide/coc-tsserver
"pretty-ts-errors.serverName": "tsserver",
(Default)
- coc-volar:
- repository: https://github.com/yaegassy/coc-volar
- Options are same as coc-tsserver's ones. (coc-volar actually calls coc-tsserver)
- typescript-language-server:
- repository: https://github.com/typescript-language-server/typescript-language-server
"pretty-ts-errors.serverName": "xxxxxxxx",
(It depends on your configuration)
- vtsls:
- repository: https://github.com/yioneko/vtsls
"pretty-ts-errors.serverName": "xxxxxxxx",
(It depends on your configuration)
- coc-tsserver:
-