nvim: improve cspell.json file handling

This doesn't handle looking for workspace level files, but will stop
the "Add word to dictionary" code action from creating random
cspell.json files in whatever vim considers to be the current working
directory.

Eventually, I'd like to move this all into neoconf.json, but this is
better than the current, non functional state
This commit is contained in:
Paul Stemmet 2024-09-07 16:05:42 +00:00
parent afaf382e25
commit 38568df712
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
1 changed files with 10 additions and 0 deletions

View File

@ -144,8 +144,12 @@ return {
-- CSpell setup
local cspell = require 'cspell'
local cspell_config_json = function(_)
return vim.fn.stdpath('config') .. '/cspell.json'
end
local cspell_opts = {
config = {
find_json = cspell_config_json,
on_add_to_json = function(payload)
if vim.fn.executable('jq') == 0 then return end
@ -172,6 +176,12 @@ return {
end,
}
-- Ensure our config file exists, otherwise cspell complains
local uv = (vim.uv or vim.loop);
if not uv.fs_stat(cspell_config_json()) then
vim.fn.writefile({'{}'}, cspell_config_json())
end
opts.sources = vim.tbl_extend('force', opts.sources or {}, {
cspell.diagnostics.with(cspell_opts),
cspell.code_actions.with(cspell_opts),