uga-rosa / cmp-dictionary

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

[Question]: Dynamically swap or change a dictionary with a command or mapping #24

Closed davidsierradz closed 2 years ago

davidsierradz commented 2 years ago

Hi!

Is possible to change dictionaries on-demand?

I have cmp-dictionary configured with:

require('cmp_dictionary').setup({
  dic = {
    -- ['*'] = '/usr/share/dict/words',
    ['markdown'] = '/path/to/es.dict',
  },
  -- The following are default values, so you don't need to write them if you don't want to change them
  exact = 3,
  first_case_insensitive = true,
  async = true,
  -- capacity = 5,
  -- debug = false,
})

I tried:

:lua require('cmp_dictionary').setup({dic={['markdown'] = '/path/to/en.dict'}})

And after:

:lua require("cmp_dictionary.caches").update()

After that, I try to see the current config:

:lua dump(require("cmp_dictionary.config"))
{                                                                                                       
  config = {
    async = false,
    capacity = 5,
    debug = false,
    dic = {
      ["*"] = <1>{},
      markdown = "/path/to/en.dict"
    },
    exact = 2,
    first_case_insensitive = false
  },
  default = {
    async = false,
    capacity = 5,
    debug = false,
    dic = {
      ["*"] = <table 1>
    },
    exact = 2,
    first_case_insensitive = false
  },
  get = <function 1>,
  ready = true,
  setup = <function 2>
}

I see the new dictionary in config (I notice that all my other settings get back to the defaults), but I'm still seeing only the words of the previous dict (not the new one).

Is this possible?

Thank you!

uga-rosa commented 2 years ago

The setup is there to put in default values for unspecified settings, so I think you can change the config directly after the setup.

tzws commented 2 years ago

@davidsierradz similar to https://github.com/uga-rosa/cmp-dictionary/issues/23

uga-rosa commented 2 years ago

Specifically

require("cmp_dictionary.config").config.dic.markdown = "path/to/en.dict"
uga-rosa commented 2 years ago

Since @davidsierradz seem to want to dynamically switch dictionaries for a single file type, perhaps #23 is not the solution.

davidsierradz commented 2 years ago

require("cmp_dictionary.config").config.dic.markdown = "path/to/en.dict"

Thanks! I can confirm this works:

lua require("cmp_dictionary.config").config.dic.markdown = "/path/to/en.dict"; require("cmp_dictionary.caches").update();