rachartier / tiny-code-action.nvim

A Neovim plugin that provides a simple way to run and visualize code actions with Telescope.
MIT License
105 stars 2 forks source link

[Bug] No diff preview and lots of errors #14

Open Ajaymamtora opened 1 month ago

Ajaymamtora commented 1 month ago

When opening the picker, the actions are listed but the preview is empty and I get this error every time I try and scroll through the actions:

   Error  15:04:53 msg_show.emsg

E5108: Error executing lua: ...-code-action.nvim/lua/tiny-code-action/backend/delta.lua:62: attempt to index local 'action_result' (a nil value)
stack traceback:
    ...-code-action.nvim/lua/tiny-code-action/backend/delta.lua:62: in function 'get_command'
    ...lescope.nvim/lua/telescope/previewers/term_previewer.lua:208: in function 'preview'
    ...share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:1217: in function 'refresh_previewer'
    ...share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:1158: in function 'set_selection'
    ...share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:917: in function 'move_selection'
    ...e/nvim/lazy/telescope.nvim/lua/telescope/actions/set.lua:39: in function 'run_replace_or_original'
    ...re/nvim/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'shift_selection'
    .../nvim/lazy/telescope.nvim/lua/telescope/actions/init.lua:87: in function 'run_replace_or_original'
    ...re/nvim/lazy/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
    ...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:293: in function <...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:292>

this is my config

config.tiny_code_actions = function()
  local opts = {
    --- The backend to use, currently only "vim" and "delta" are supported
    backend = "delta",
    backend_opts = {
      delta = {
        -- If you want to override the delta command
        override_cmd = nil,

        -- If you want to use git config or not, if you set config_path, it needs to be false
        use_git_config = true,

        -- If you have a custom config path
        config_path = nil,
      },
    },
    -- telescope_opts = {
    --   layout_strategy = "vertical",
    --   layout_config = {
    --     width = 0.7,
    --     height = 0.9,
    --   },
    -- },
    -- 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" } },
    },
  }
  require("tiny-code-action").setup(opts)
end

...

modules["rachartier/tiny-code-action.nvim"] = {
  lazy = true,
  event = "LspAttach",
  dependencies = {
    { "nvim-lua/plenary.nvim" },
    { "nvim-telescope/telescope.nvim" },
  },
  version = false,
  config = editor_config.tiny_code_actions,
}

image

rachartier commented 1 month ago

I would suggest to not copy all the default opts, as it can changes in the future. By not setting it, it will takes default values anyway.

I've greatly simplified to setup of delta some times ago, so now it is configured like so:

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

In your setup, delete all except backend, and it should work.

Ajaymamtora commented 1 month ago

I would suggest to not copy all the default opts, as it can changes in the future. By not setting it, it will takes default values anyway.

I've greatly simplified to setup of delta some times ago, so now it is configured like so:

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

In your setup, delete all except backend, and it should work.

Deleted everything, still the same issue

rachartier commented 1 month ago

I've added a check that verify is code action is nil.

But it means that no code action can be resolved, which is weird. How do you setup lua_ls ?