nvim/plug: add null-ls.nvim@main, cspell.nvim@main

These gives us back the ability to use cspell, which was lost in the
transition from coc-nvim to our current lua based setup.

However, it requires the following to take effect:

1. Have nodejs installed (nvm is fine)
2. Run ':MasonInstall cspell'
3. Run ':PackerCompile'
4. Restart

All goes well, when you next open nvim, you should have cspell powered
spell checking and :LspInfo should show null-ls running.

Word substitutes triggered via:
  @Buffer.Lsp.N.Leader.CodeAction

Next/Prev word (or other diagnostic) via:
  @Global.N.DiagnosticNext
  @Global.N.DiagnosticPrev

Where @ = nvim/lua/psoxizsh/key/bind.lua
This commit is contained in:
Paul Stemmet 2023-06-08 15:10:46 +00:00
parent 5311f2013e
commit 3e1e459c50
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,58 @@
return function()
local nls, util = require 'null-ls', require 'psoxizsh.util'
local S = {
builtin = nls.builtins,
cspell = require 'cspell',
}
local flatten = function(list)
local out = {}
for _, l in ipairs(list) do
for _, v in ipairs(l) do
table.insert(out, v)
end
end
return out
end
local if_exec = function(args)
return vim.fn.executable(args[1]) == 1 and vim.list_slice(args, 2) or {}
end
local cspell_event_handler = function(cfg, params, action)
if action == 'add_to_json' and vim.fn.executable('jq') == 1 then
local cmd = "cat %s | jq -S '.words |= sort' | tee %s > /dev/null"
os.execute(cmd:format(cfg, cfg))
end
end
local cspell_post_handler = function(diagnostic)
local level, levels = diagnostic.severity, vim.diagnostic.severity
-- Cap maximum severity of spelling mistakes
if level == levels.ERROR or level == levels.WARN then
diagnostic.severity = levels.INFO
end
end
local cspell_options = {
config = {
on_success = cspell_event_handler,
},
diagnostics_postprocess = cspell_post_handler
}
local defaults = {
sources = flatten {
if_exec { 'cspell',
S.cspell.diagnostics.with(cspell_options),
S.cspell.code_actions.with(cspell_options),
},
},
}
nls.setup(util.mconfig('config.null-ls', defaults))
end

View File

@ -120,6 +120,19 @@ local plugins = {
{ 'luochen1990/rainbow' },
{ 'sheerun/vim-polyglot' },
-- Framework for integrating non-LSP sources into nvim's LSP framework
{ 'jose-elias-alvarez/null-ls.nvim',
as = 'null-ls',
branch = 'main',
requires = { 'nvim-lua/plenary.nvim' },
after = 'cspell',
config = require 'psoxizsh.plugins.config.null-ls',
},
{ 'davidmh/cspell.nvim',
as = "cspell",
branch = 'main',
},
-- Maker / diagnostics listing
{ 'folke/trouble.nvim',
requires = { 'kyazdani42/nvim-web-devicons' },