rachartier/tiny-code-action.nvim

github github
lspneovim-0.5
stars 187
issues 0
subscribers 3
forks 2
CREATED

2024-07-22

UPDATED

last month


📇 tiny-code-action.nvim

A Neovim plugin that provides a simple way to run and visualize code actions with Telescope.

The code action protocol is nearly fully implemented in this plugin, so you can use it with any language server, even with, like in the preview, Omnisharp which uses partial code actions.

[!WARNING] I have not tested on all LSP, so do not hesitate to open an issue if it doesn't work for you.

🖼️ Preview

Delta

tinycode_1

Vim

tinycode_vimdiff_1

Difftastic

tinycode_difftastic_1

Installation

📥 Installation

[!NOTE] This plugins comes with NerdFonts icons by default. If you don't want to use them, you can remove them from the signs option.

With Lazy.nvim:

{
    "rachartier/tiny-code-action.nvim",
    dependencies = {
        {"nvim-lua/plenary.nvim"},
        {"nvim-telescope/telescope.nvim"},
    },
    event = "LspAttach",
    config = function()
        require('tiny-code-action').setup()
    end
}

And add the following snippet to your keymaps:

vim.keymap.set("n", "<leader>ca", function()
    require("tiny-code-action").code_action()
end, { noremap = true, silent = true })

⚙️ Options

[!NOTE] To use the delta backend you must install delta dandavison/delta

[!WARNING] Due to some limitations, the delta backend can be slow if the action is really big. If you want optimal performance, use the vim backend.

require("tiny-code-action").setup({
    --- The backend to use, currently only "vim", "delta" and "difftastic" are supported
    backend = "vim",
    backend_opts = {
        delta = {
            -- Header from delta can be quite large.
            -- You can remove them by setting this to the number of lines to remove
            header_lines_to_remove = 4,

            -- The arguments to pass to delta
            -- If you have a custom configuration file, you can set the path to it like so:
            -- args = {
            --     "--config" .. os.getenv("HOME") .. "/.config/delta/config.yml",
            -- }
            args = {
                "--line-numbers",
            },
        },
        difftastic = {
            -- Header from delta can be quite large.
            -- You can remove them by setting this to the number of lines to remove
            header_lines_to_remove = 1,

            -- The arguments to pass to difftastic
            args = {
                "--color=always",
                "--display=inline",
                "--syntax-highlight=on",
            },
        },
    },
    telescope_opts = {
        layout_strategy = "vertical",
        layout_config = {
            width = 0.7,
            height = 0.9,
            preview_cutoff = 1,
            preview_height = function(_, _, max_lines)
                local h = math.floor(max_lines * 0.5)
                return math.max(h, 10)
            end,
        },
    },
    -- The icons to use for the code actions
    -- You can add your own icons, you just need to set the exact action's kind of the code action
    -- You can set the highlight like so: { link = "DiagnosticError" } or  like nvim_set_hl ({ fg ..., bg..., bold..., ...})
    signs = {
        quickfix = { "󰁨", { link = "DiagnosticInfo" } },
        others = { "?", { link = "DiagnosticWarning" } },
        refactor = { "", { link = "DiagnosticWarning" } },
        ["refactor.move"] = { "󰪹", { link = "DiagnosticInfo" } },
        ["refactor.extract"] = { "", { link = "DiagnosticError" } },
        ["source.organizeImports"] = { "", { link = "TelescopeResultVariable" } },
        ["source.fixAll"] = { "", { link = "TelescopeResultVariable" } },
        ["source"] = { "", { link = "DiagnosticError" } },
        ["rename"] = { "󰑕", { link = "DiagnosticWarning" } },
        ["codeAction"] = { "", { link = "DiagnosticError" } },
    },
})

Filters

You can filter the code actions by setting the filters option.

{
    str = "..." -- Filter to title
    kind = "refactor" -- Filter to the kind
    client = "omnisharp" -- Filter to the client
}

Example:


require("tiny-code-action").code_action({
        filters = {
        kind = "refactor",
        str = "Wrap"
    }
})

❓ FAQ:

  • How to look like the preview?
    • You can find my delta configuration here: rachartier/dotfiles/delta
    • Then you can set the config_path to the path of your configuration file.