aznhe21 / actions-preview.nvim

Fully customizable previewer for LSP code actions.
GNU General Public License v3.0
400 stars 11 forks source link

lazy load logic issue with highlight command option #53

Closed KevinNitroG closed 2 months ago

KevinNitroG commented 2 months ago

Because the plugin is lazy loaded, it hasn't loaded while declaring opts.highlight_command. Here's my current config which make my nvim got error.

{
  "aznhe21/actions-preview.nvim",
  keys = {
    {
      "<leader>la",
      function()
        require("actions-preview").code_actions()
      end,
      mode = { "v", "n" },
      desc = "Action Preview | Open",
      silent = true,
    },
  },
  opts = {
    highlight_command = {
      vim.fn.executable "delta" == 1 and require("actions-preview.highlight").delta(),
    },
  },
}

I suggest just making opts.highlight_command receive a string (name of diff) and checking it behind the scenes.

aznhe21 commented 2 months ago

There is no need to use vim.fn.executable in the config, as actions-preview will check for the existence of the command when it executes the command. That is, you can simply set the following in the configuration.

    highlight_command = {
      require(“actions-preview.highlight”).delta(),
    },
KevinNitroG commented 2 months ago

Thank you <3 I didn't notice that ☺️. But it's great to support lazy loading...

aznhe21 commented 2 months ago

I believe that is the responsibility of the plugin manager. I don't use lazy.nvim, so I'm not sure, but doesn't it have a mechanism for evaluating config during lazy loading?

KevinNitroG commented 2 months ago

@aznhe21 I guess it's possible to pass the opt directly in the setup like this. But it doesn't follow the convention of LazyNvim

{
  "aznhe21/actions-preview.nvim",
  keys = {
    {
      "<leader>la",
      function()
        require("actions-preview").code_actions()
      end,
      mode = { "v", "n" },
      desc = "Action Preview | Open",
      silent = true,
    },
  },
  config = function()
    require("actions-preview").setup {
      highlight_command = {
        require("actions-preview.highlight").delta(),
      },
    }
  end,
}
aznhe21 commented 2 months ago

I'm not sure what 'the convention of LazyNvim' refers to, but according to the LazyVim reference, there is a method for specifying a function in opts. You can use this.

This isn't a place for LazyVim questions, so I won't provide further support. Please continue in the appropriate forum from here.