Skip to content

Commit

Permalink
feat: add diagnostic_opts parameter
Browse files Browse the repository at this point in the history
Resolves #6
  • Loading branch information
ravibrock committed Jul 10, 2024
1 parent 85022f4 commit 1eff19e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ Pass any of the following options to `require("spellwarn").setup()`:
spellrare = "INFO",
},
prefix = "possible misspelling(s): ", -- prefix for each diagnostic message
diagnostic_opts = { severity_sort = true }, -- options for diagnostic display
}
```
Most options are overwritten (e.g. passing `ft_config = { python = false }` will mean that `alpha`, `mason`, etc. are set to true) but `severity` is merged, so that passing `spellbad = "HINT"` won't cause `spellcap` to be nil. You can pass any of `cursor`, `iter`, `treesitter`, `false`, or `true` as options to `ft_config`. The default method is `cursor`, which iterates through the buffer with `]s`. There is also `iter`, which uses Treesitter (if available) and the Lua API. Finally, `false` disables Spellwarn for that filetype and `true` uses the default (`cursor`).
Most options are overwritten (e.g. passing `ft_config = { python = false }` will mean that `alpha`, `mason`, etc. are set to true) but `severity` and `diagnostic_opts` are merged, so that (for example) passing `{ spellbad = "HINT" }` won't cause `spellcap` to be nil. You can pass any of `cursor`, `iter`, `treesitter`, `false`, or `true` as options to `ft_config`. The default method is `cursor`, which iterates through the buffer with `]s`. There is also `iter`, which uses Treesitter (if available) and the Lua API. Finally, `false` disables Spellwarn for that filetype and `true` uses the default (`cursor`).

*Note: `iter` doesn't show `spellcap` errors, but works well other than that. I recommend it.*

Expand Down
2 changes: 1 addition & 1 deletion lua/spellwarn/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function M.update_diagnostics(opts, bufnr)
end
vim.diagnostic.reset(namespace, bufnr)
-- TODO: Add suffix diagnostics with type of spelling error the way that LSP diagnostics do
vim.diagnostic.set(namespace, bufnr, diags, { severity_sort = true })
vim.diagnostic.set(namespace, bufnr, diags, opts.diagnostic_opts)
end

function M.setup(opts)
Expand Down
5 changes: 4 additions & 1 deletion lua/spellwarn/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ local defaults = {
spellrare = "INFO",
},
prefix = "possible misspelling(s): ", -- prefix for each diagnostic message
diagnostic_opts = { severity_sort = true }, -- options for diagnostic display
}

function M.setup(opts)
-- With most options we want to overwrite the defaults, but with `severity` we want to extend
-- With most options we want to overwrite the defaults, but with `severity` and `diagnostic_opts` we want to extend
local diagnostic_opts = defaults.diagnostic_opts
local severity = defaults.severity
opts = opts or {}
defaults = vim.tbl_extend("force", defaults, opts)
defaults.diagnostic_opts = vim.tbl_extend("force", diagnostic_opts, opts.diagnostic_opts or {})
defaults.severity = vim.tbl_extend("force", severity, opts.severity or {})
require("spellwarn.diagnostics").setup(defaults)

Expand Down

0 comments on commit 1eff19e

Please sign in to comment.