cmp-tmux icon indicating copy to clipboard operation
cmp-tmux copied to clipboard

This plugin must be loaded after cmp to make options work

Open lljbash opened this issue 1 year ago • 4 comments

AFAIK a lot of people use cmp-tmux as a dependency of cmp for convenience. As a result, option set during cmp setup won't effect the source.config which have already been created during cmp-tmux setup.

Please consider using lazy-initialization instead or at least mention this unexpected behaviour in README.

lljbash avatar Jan 08 '24 10:01 lljbash

mention this unexpected behaviour

Sorry, but I don't completely understand what you mean here. From what I can tell cmp-tmux registers itself just like other extensions for cmp.

Care to elaborate on this?

andersevenrud avatar Jan 08 '24 14:01 andersevenrud

Thank you for your prompt attention to my issue.

In lua/cmp_tmux/source.lua,

local config = require('cmp.config')

requires cmp.setup to be called or you won't get anything valuable.

However, people like me may get used to write configures like

-- lazy.nvim
return {
  {
    "hrsh7th/nvim-cmp",
    event = "InsertEnter",
    dependencies = {
      ...
      "andersevenrud/cmp-tmux",
      ...
    },
    name = "cmp",
    config = function()
      ...
      local cmp = require("cmp")
      ...
      cmp.setup({
        ...
        sources = {
          ...
          {
            name = "tmux",
            option = {
              label = "",
              trigger_characters = {},
            },
          },
          ...
        },
        ...
      })
      ...
    end,
  },
}

where cmp.tmux config will be loaded before that setup.

I have spotted a few other issues (like #27) that could be for the same reason.

lljbash avatar Jan 10 '24 02:01 lljbash

Aha! I actually use pretty much the same setup as you, but actually haven't noticed this!

I'm a little bit busy at the moment, so if you have something in mind that could solve this feel free to open a pull-request.

andersevenrud avatar Jan 10 '24 19:01 andersevenrud

Actually I have found a workaround for this issue by not using option provided by your plugin:

  1. using { name = "tmux", keyword_length = 2, trigger_characters = {} } to configure trigger rules.
  2. using lspkind.cmp_format({ before = function()... to remove that label.

But I'm still interested in improving your plugin. There should be 2 approaches:

  1. lazy-initializing source
  2. adding a setup stage like uga-rosa/cmp-dictionary

I would suggest remove all redundant options which have already been provided by cmp and move the others into a setup stage.

lljbash avatar Jan 11 '24 04:01 lljbash