merge: develop <--- feature/null-ls-cspell
* HEAD | \ | *3e1e459
<github@luxolus.com> nvim/plug: add null-ls.nvim@main, cspell.nvim@main | *5311f20
<github@luxolus.com> nvim/plug: rm cmp-spell | / | develop Signed-off-by: Bazaah <github@luxolus.com>
This commit is contained in:
commit
f02c998488
|
@ -1,47 +0,0 @@
|
|||
return function()
|
||||
local util, au = require 'psoxizsh.util', require 'psoxizsh.autocmd'
|
||||
local o, l, fn = vim.opt, vim.opt_local, vim.fn
|
||||
-- Yes, this is a bad idea, but I don't really feel like
|
||||
-- writing my own recursive ascent parser for file paths right now
|
||||
--
|
||||
-- *whips self* Don't randomly require unrelated modules!
|
||||
local ulsp = require 'lspconfig.util'
|
||||
|
||||
local defaults = {
|
||||
-- Languages to recognize, only languages[1] is used for user dictionaries
|
||||
-- leave this alone unless you've read the entirety of ':h spell' and
|
||||
-- understand what you're doing
|
||||
languages = { 'en_us', 'cjk' },
|
||||
-- Spell options (leave this alone)
|
||||
options = { 'camel' },
|
||||
-- File names that indicate the root repo directory
|
||||
root_patterns = { '.vim', '.git', '.hg', 'Cargo.toml', 'package.json' },
|
||||
-- File glob to activate spell checking on, e.g '*.md'
|
||||
file_pattern = '*',
|
||||
}
|
||||
|
||||
local merged = util.mconfig('config.cmp-spell', defaults)
|
||||
local cfg = {
|
||||
spell_fname = string.format('%s.%s.add', 'words', o.encoding:get()),
|
||||
searcher = ulsp.root_pattern(unpack(merged.root_patterns)),
|
||||
}
|
||||
|
||||
_G._psoxizsh_config_cmp_spell_on_enter = function()
|
||||
local checked, repo_root = {}, cfg.searcher(fn.getcwd())
|
||||
|
||||
-- We look in these places for spell files
|
||||
-- 1. <workspace root>/.vim/
|
||||
-- 2. ~/.config/nvim
|
||||
-- 3. $PSOXIZSH/nvim/spellfile
|
||||
if repo_root then table.insert(checked, repo_root .. '/.vim') end
|
||||
vim.list_extend(checked, { '~/.config/nvim', vim.env.PSOXIZSH .. '/nvim/spellfile' })
|
||||
checked = vim.tbl_map(function(p) return fn.expand(p) .. '/' .. cfg.spell_fname end, checked)
|
||||
|
||||
l.spell = true
|
||||
l.spelllang = merged.languages
|
||||
l.spelloptions = merged.options
|
||||
l.spellfile = checked
|
||||
end
|
||||
|
||||
au.PsoxSpellSettings {{ 'BufEnter', merged.file_pattern, 'call v:lua._psoxizsh_config_cmp_spell_on_enter()' }}
|
||||
end
|
|
@ -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
|
|
@ -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' },
|
||||
|
@ -153,10 +166,6 @@ local plugins = {
|
|||
{ 'hrsh7th/cmp-buffer' },
|
||||
{ 'hrsh7th/cmp-cmdline' },
|
||||
{ 'dmitmel/cmp-cmdline-history' },
|
||||
{ 'f3fora/cmp-spell',
|
||||
after = { 'lspconfig' },
|
||||
config = require 'psoxizsh.plugins.config.cmp-spell'
|
||||
},
|
||||
|
||||
-- Tree sitter
|
||||
{ 'nvim-treesitter/nvim-treesitter',
|
||||
|
|
Loading…
Reference in New Issue