-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there a way to beautify the cspell.json somehow? #19
Comments
There is, from the README: --- Callback after a successful execution of a code action.
---@param cspell_config_file_path string|nil
---@param params GeneratorParams
---@action_name 'use_suggestion'|'add_to_json'|'add_to_dictionary'
on_success = function(cspell_config_file_path, params, action_name)
-- For example, you can format the cspell config file after you add a word
if action_name == 'add_to_json' then
os.execute(
string.format(
"cat %s | jq -S '.words |= sort' | tee %s > /dev/null",
cspell_config_file_path,
cspell_config_file_path
)
)
end
-- Note: The cspell_config_file_path param could be nil for the
-- 'use_suggestion' action
end That example uses |
this doesn't work tho -- it creates a new cspell.json file at the current working directory, rather than the
even if swapping out cspell_config_file_path for cspellConfigFile, it's still the local path :-\ |
It would be easier to debug with a minimal configuration. You can take this file as an example: https://github.com/davidmh/cspell.nvim/blob/0e9c586bd7f7ab3f1f2f000a084121203e0ee62c/tests/minimal_init.lua And you can add your own configuration right after this line: cspell.nvim/tests/minimal_init.lua Line 35 in 0e9c586
Something like: local null_ls = require("null-ls")
local cspell = require("cspell")
local sources = {
cspell.diagnostics,
cspell.code_actions,
}
null_ls.setup({ sources = sources }) Then you can start Neovim using that configuration as: nvim -u minimal_init.lua some-other-file-to-lint.ts |
I'm running into the issue where To beautify with a lua only solution, I created the following: local cspell_opts = {
config = {
encode_json = function(cspell_tbl)
local json = vim.json.encode(cspell_tbl) or "null"
local buf = vim.api.nvim_create_buf(false, true)
if buf > 0 then
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { json })
vim.api.nvim_buf_set_option(buf, "filetype", "json")
local conform = require("conform")
conform.format({ bufnr = buf })
return table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
end
return json
end,
}
}
require("null-ls").setup({
sources = {
cspell.diagnostics.with(cspell_opts),
cspell.code_actions.with(cspell_opts),
}
}) It does rely on a 3rd party formatter plugin, which I have configured to use prettierd for json files, but I imagine this could also work with null-ls formatting. |
@NullVoxPopuli this should be fixed with #26 |
Was hoping I could somehow format the cspell.json to help with conflict management as I sync the config file between machines.
Looking at the README, I only see string -> table transforms, and nothing about the actual file
The text was updated successfully, but these errors were encountered: