uga-rosa / cmp-dictionary

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

How to configure filetype specific dictionaries in version 3? #59

Closed kiryph closed 5 months ago

kiryph commented 5 months ago

Current config:

local dict = require("cmp_dictionary")
dict.setup({
    dic = {
        ['gap'] = '/Users/kiryph/.vim/GAPWORDS',
    },
    -- The following are default values, so you don't need to write them if you don't want to change them
    exact_length = 3, -- how many characters at the beginning are used as the exact match.
    first_case_insensitive = false,
    async = false,
    debug = false,
    max_nubmer_items = 0,
})
dict.switcher({
  filetype = {
    gap = '/Users/kiryph/.vim/GAPWORDS',
  },
})

As far as I see it stopped working. No completion for gap words.

https://github.com/gap-system/gap/blob/master/etc/vim/gap.vim#L170-L173

New version complains that switcher is deprecated and I see no help in the documentation.

uga-rosa commented 5 months ago

Since setup merges options each time it is called, you can use autocmd to update only the paths.

require("cmp_dictionary").setup({
  exact_length = 3,
})

local dict = {
  ["*"] = { "/path/to/global_dict" },
  gap = { "/path/to/gap_dict" },
}

vim.api.nvim_create_autocmd("FileType", {
  pattern = "*",
  callback = function(ev)
    require("cmp_dictionary").setup({
      paths = dict[ev.match] or dict["*"],
    })
  end,
})
uga-rosa commented 5 months ago

There are several invalid option names, please check the help and correct them. :h cmp-dictionary-options