davidmh / cspell.nvim

A companion plugin for null-ls/none-ls, adding support for CSpell diagnostics and code actions.
82 stars 13 forks source link

fix: avoid overwriting JSON with a default one when async is enabled #45

Closed Frederick888 closed 8 months ago

Frederick888 commented 8 months ago

When read_config_synchronously = false, as the actions are often generated before the JSON is read, when an action is executed, it could overwrite an existing JSON config with a default one due to opts.cspell being empty.

So first of all, this patch makes a fresh query to CONFIG_INFO_BY_CWD, which allows actions to correctly reuse it if the async reading is done.

If the async reading is still in-progress, the misspelled word is cached in CACHED_JSON_WORDS, and gets added with other cached words once the reading is done.

davidmh commented 8 months ago

Your approach makes sense to me.

I'm AFK for the next couple of days so I can't test it manually. Would you mind adding a test for it?