Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidmh/cspell.nvim
A companion plugin for null-ls/none-ls, adding support for CSpell diagnostics and code actions.
https://github.com/davidmh/cspell.nvim
neovim none-ls-sources null-ls-sources nvim
Last synced: 3 months ago
JSON representation
A companion plugin for null-ls/none-ls, adding support for CSpell diagnostics and code actions.
- Host: GitHub
- URL: https://github.com/davidmh/cspell.nvim
- Owner: davidmh
- Created: 2023-04-23T18:23:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-16T03:09:08.000Z (6 months ago)
- Last Synced: 2024-05-16T05:22:25.843Z (6 months ago)
- Topics: neovim, none-ls-sources, null-ls-sources, nvim
- Language: Lua
- Homepage:
- Size: 914 KB
- Stars: 66
- Watchers: 2
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cspell.nvim
A companion plugin for [nvimtools/none-ls.nvim](https://github.com/nvimtools/none-ls.nvim),
adding support for [cspell] diagnostics and code actions.## Diagnostics
```lua
local cspell = require('cspell')
require("null-ls").setup {
sources = {
cspell.diagnostics
}
}
```### Defaults
- Filetypes: `{}`
- Method: `diagnostics`
- Command: `cspell`
- Args: dynamically resolved (see [diagnostics source])## Code Actions
```lua
local cspell = require('cspell')
require("null-ls").setup {
sources = {
cspell.diagnostics,
cspell.code_actions,
}
}
```### Defaults
- Filetypes: `{}`
- Method: `code_action`## Configuration options
All the configuration properties are optional and they're used for the code actions.
But if you define them, make sure to add them to both the diagnostics **and** the code_actions.
We need to do that to start reading and parsing the CSpell configuration asynchronously as soon
as we get the first diagnostic.```lua
local config = {
-- The CSpell configuration file can take a few different names this option
-- lets you specify which name you would like to use when creating a new
-- config file from within the `Add word to cspell json file` action.
--
-- See the currently supported files in https://github.com/davidmh/cspell.nvim/blob/main/lua/cspell/helpers.lua
config_file_preferred_name = 'cspell.json',--- A way to define your own logic to find the CSpell configuration file.
---@params cwd The same current working directory defined in the source,
-- defaulting to vim.loop.cwd()
---@return string|nil The path of the json file
find_json = function(cwd)
end,-- Will find and read the cspell config file synchronously, as soon as the
-- code actions generator gets called.
--
-- If you experience UI-blocking during the first run of this code action, try
-- setting this option to false.
-- See: https://github.com/davidmh/cspell.nvim/issues/25
read_config_synchronously = true,---@param cspell string The contents of the CSpell config file
---@return table
decode_json = function(cspell_str)
end,---@param cspell table A lua table with the CSpell config values
---@return string
encode_json = function(cspell_tbl)
end,---@param payload UseSuggestionSuccess
on_use_suggestion = function(payload)
-- Includes:
payload.misspelled_word
payload.suggestion
payload.cspell_config_path
payload.generator_params
end---@param payload AddToJSONSuccess
on_add_to_json = function(payload)
-- Includes:
payload.new_word
payload.cspell_config_path
payload.generator_params-- For example, you can format the cspell config file after you add a word
os.execute(
string.format(
"jq -S '.words |= sort' %s > %s.tmp && mv %s.tmp %s",
payload.cspell_config_path,
payload.cspell_config_path,
payload.cspell_config_path,
payload.cspell_config_path
)
)
end---@param payload AddToDictionarySuccess
on_add_to_dictionary = function(payload)
-- Includes:
payload.new_word
payload.cspell_config_path
payload.generator_params
payload.dictionary_path-- For example, you can sort the dictionary after adding a word
os.execute(
string.format(
"sort %s -o %s",
payload.dictionary_path,
payload.dictionary_path
)
)
end--- DEPRECATED
--- Callback after a successful execution of a code action.
---@param cspell_config_file_path string|nil
---@param params GeneratorParams
---@param action_name 'use_suggestion'|'add_to_json'|'add_to_dictionary'
on_success = function(cspell_config_file_path, params, action_name)
end
}local cspell = require('cspell')
require("null-ls").setup {
sources = {
cspell.diagnostics.with({ config = config }),
cspell.code_actions.with({ config = config }),
}
}
```### Notes
- The code action source depends on the diagnostics, so make sure to register it too.
## Tests
The test suite depends on plenary.nvim.
Run `./tests/run.sh` in the root of the project to run the suite or use [neotest]
to run individual tests from within Neovim.To avoid a dependency on any plugin managers, the test suite will set up its
plugin runtime under the `./tests` directory to always have a plenary version
available.If you run into plenary-related issues while running the tests, make sure you
have an up-to-date version of the plugin by clearing that cache with
`rm -rf .tests/`.All tests expect the latest Neovim master.
# TODO
- [ ] Custom configuration examples
# Credits
These sources were initially written in jose-elias-alvarez/null-ls.nvim, with
contributions from: [@JA-Bar], [@PumpedSardines], [@Saecki], [@Sloff], [@marianozunino],
[@mtoohey31] and [@yoo].[null-ls]: https://github.com/jose-elias-alvarez/null-ls.nvim
[cspell]: https://github.com/streetsidesoftware/cspell
[diagnostics source]: https://github.com/davidmh/cspell.nvim/blob/main/lua/cspell/diagnostics/init.lua
[@JA-Bar]: https://github.com/JA-Bar
[@PumpedSardines]: https://github.com/PumpedSardines
[@Saecki]: https://github.com/Saecki
[@Sloff]: https://github.com/Sloff
[@marianozunino]: https://github.com/marianozunino
[@mtoohey31]: https://github.com/mtoohey31
[@yoo]: https://github.com/yoo
[neotest]: https://github.com/nvim-neotest/neotest