nvim/plug: +cmp-spell@master

This commit adds integration for the builtin spell checker to our auto
completion engine.

Now, unfortunately, it is not nearly as intelligent as coc-spell-checker
is, and is missing _lots_ of common words that I/we use every day.

To alleviate this a bit, there are three spell files that can be used to
add/remove/override spell words:

1. <workspace>/.vim/words.utf-8.add
2. ~/.config/nvim/words.utf-8.add
3. $PSOXIZSH/nvim/spellfile/words.utf-8.add

You may also easily add / remove words from a given file via:

- [count]<Leader>ss: Whitelist word in `count` spell file, defaulting to
  the lowest write-able file
- [count]<Leader>sw: Blacklist word in `count` spell file, defaulting to
  the lowest write-able file
- [count]<Leader>sus: Undo whitelist word in `count` spell file
- [count]<Leader>suw: Undo blacklist word in `count` spell file
- ]s: Next bad word
- [s: Previous bad word
This commit is contained in:
Paul Stemmet 2022-09-10 07:29:57 +00:00
parent 267fb252c7
commit 178d0a7340
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
4 changed files with 62 additions and 0 deletions

View File

@ -20,6 +20,11 @@ M.Global.N {
ReloadConfig = B { 'Reload Neovim configuration' , key = 'vs' , } ,
ToggleGutter = B { 'Toggle Neovim gutter' , key = 'N' , } ,
SpellWhiteList = B { 'Whitelist <cword> to [count] spellfile' , key = 'ss' , action = 'zg' , } ,
SpellBlackList = B { 'Blacklist <cword> to [count] spellfile' , key = 'sw' , action = 'zw' , } ,
SpellWhiteListUndo = B { 'Undo whitelist <cword> in [count] spellfile' , key = 'sus' , action = 'zug' , } ,
SpellBlackListUndo = B { 'Undo blacklist <cword> to [count] spellfile' , key = 'suw' , action = 'zuw' , } ,
ToggleBuffers = B { 'Open buffer list' , key = '<Tab>' , action = '<cmd>Neotree toggle reveal float source=buffers<CR>' , } ,
ToggleGitStatus = B { 'Open Git status float' , key = 'gs' , action = '<cmd>Neotree float git_status<CR>' , } ,

View File

@ -0,0 +1,52 @@
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' })
for i, path in ipairs(checked) do
if path and fn.exists(fn.expand(path)) then
checked[i] = path .. '/' .. cfg.spell_fname
end
end
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

View File

@ -64,6 +64,7 @@ return function()
},
{
{ name = 'buffer', keyword_length = 2 },
{ name = 'spell', max_item_count = 3, keyword_length = 3 },
}
)

View File

@ -138,6 +138,10 @@ local plugins = {
{ 'hrsh7th/cmp-vsnip' },
{ 'hrsh7th/cmp-path' },
{ 'hrsh7th/cmp-buffer' },
{ 'f3fora/cmp-spell',
after = { 'lspconfig' },
config = require 'psoxizsh.plugins.config.cmp-spell'
},
-- Tree sitter
{ 'nvim-treesitter/nvim-treesitter',