Skip to content

z0rzi/format-ts-errors.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

format-ts-errors.nvim

A very simple Neovim plugin to format TypeScript errors.

How it looks

big small

Requirements

This plugin uses prettier to format the types.

Installation

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,
},

How it works

This plugin uses the format option of the vim.diagnostic.open_float function, to:

  1. Get the diagnostic message
  2. Identify the parts of the message which are types
  3. Format the types using prettier
  4. Place the formatted types in markdown code blocks
  5. Send the formatted message to the native vim.diagnostic.open_float

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages