uga-rosa / cmp-dictionary

A dictionary completion source for nvim-cmp
MIT License
236 stars 16 forks source link

dictionary path is only set on entering the first buffer #52

Closed moetayuko closed 10 months ago

moetayuko commented 10 months ago

Env

My config looks like this, and nvim-cmp is loaded on InsertEnter

{
  "hrsh7th/nvim-cmp",
  dependencies = {
    {
      "uga-rosa/cmp-dictionary",
      config = function(_, opts)
        local dict = require("cmp_dictionary")
        dict.setup(opts)
        dict.switcher({ spelllang = {
          en = "/usr/share/dict/words",
        } })
      end,
    },
  },
  opts = function(_, opts)
    local cmp = require("cmp")
    opts.sources = cmp.config.sources(vim.list_extend(opts.sources, {
      {
        name = "dictionary",
        keyword_length = 2,
      },
    }))
  end,
}

Since I set the dictionary path for spelllang=en only, the path will be appended to vim.opt_local.dictionary (notice that it's buffer-local!) on OptionSet https://github.com/uga-rosa/cmp-dictionary/blob/f076c6b071e6117d2cbb26d53327ff21fc22fdb8/lua/cmp_dictionary/init.lua#L76-L82

Issue

vim.opt_local.dictionary is only populated when entering the first buffer. If the first is a "normal" buffer, completion keeps working for later buffers despite vim.opt_local.dictionary being empty, for unknown reasons. However, if the first buffer is telescope or potentially other special buffers, completion won't work for the entire session.

To reproduce: # Step Operation :setlocal dictionary Has word completion?
1 start nvim N/A
2 open a file and enter insert mode /usr/share/dict/words Y
3 open another file and enter insert mode Y
# Step Operation :setlocal dictionary Has word completion?
1 start nvim N/A
2 :Telescope, then press \<esc> to switch to normal mode but not quit telescope /usr/share/dict/words N/A
3 quit telescope, open a file and enter insert mode N
uga-rosa commented 10 months ago

Please update.

moetayuko commented 10 months ago

Thanks, it's working now.