A very simple Neovim plugin to format TypeScript errors.
This plugin uses prettier
to format the types.
Using Lazy.nvim:
{
'z0rzi/format-ts-errors.nvim',
dependencies = {
'nvim-treesitter/nvim-treesitter' -- For types highlighting, optional
},
config = function()
require('format-ts-errors').setup({
prettier_path = "prettier",
mappings = {
show_diagnostic = "L", -- Show the diagnostic under the cursor
goto_next = ";j", -- Go to the next diagnostic
goto_prev = ";k", -- Go to the previous diagnostic
},
})
-- Optional, to enable highlighting of the types (requires treesitter)
vim.g.markdown_fenced_languages = { 'typescript' }
end,
},
This plugin uses the format
option of the vim.diagnostic.open_float
function, to:
- Get the diagnostic message
- Identify the parts of the message which are types
- Format the types using
prettier
- Place the formatted types in markdown code blocks
- Send the formatted message to the native
vim.diagnostic.open_float