Add cspell, exclusively use null-ls for formatting

Add cspell extension and initial cspell.json ignore list
Disable formatting in all other language servers, use null-ls
exclusively for finer control over formatters
Add additional formatters
This commit is contained in:
Evie Litherland-Smith 2023-05-17 17:03:02 +01:00
parent 90575e4eb2
commit 9afe8567fd
5 changed files with 52 additions and 13 deletions

3
.stylua.toml Normal file
View file

@ -0,0 +1,3 @@
indent_type = "Spaces"
call_parentheses = "None"
collapse_simple_statement = "Always"

19
cspell.json Normal file
View file

@ -0,0 +1,19 @@
{
"flagWords": [],
"words": [
"builtins",
"gitsigns",
"autoflake",
"beautysh",
"fixjson",
"fprettify",
"isort",
"nixfmt",
"mdformat",
"nixpkgs",
"shellharden",
"stylua"
],
"version": "0.2",
"language": "en"
}

View file

@ -1,12 +1,3 @@
-- LSP format call with options
local lsp_formatting = function(bufnr)
vim.lsp.buf.format {
bufnr = bufnr,
timeout_ms = 2000,
async = true,
}
end
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
@ -20,7 +11,18 @@ local on_attach = function(client, bufnr)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
vim.keymap.set("n", "<leader>i", lsp_formatting, bufopts)
vim.keymap.set(
"n",
"<leader>i",
function() vim.lsp.buf.format { bufnr = bufnr, timeout_ms = 2000, async = true } end,
bufopts
)
-- specific client tweaks
if client.name ~= "null-ls" then client.server_capabilities.documentFormattingProvider = false end
if client.name == "ruff_lsp" then client.server_capabilities.hoverProvider = false end
-- Attach navic and navbuddy if applicable
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, bufnr)
require("nvim-navbuddy").attach(client, bufnr)

View file

@ -1,8 +1,23 @@
local null_ls = require "null-ls"
local cspell = require "cspell"
return {
cspell.code_actions,
null_ls.builtins.code_actions.gitsigns,
cspell.diagnostics,
null_ls.builtins.formatting.alejandra,
null_ls.builtins.formatting.autoflake,
null_ls.builtins.formatting.beautysh,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.fixjson,
-- null_ls.builtins.formatting.fprettify,
null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.trim_whitespace,
null_ls.builtins.formatting.mdformat,
-- null_ls.builtins.formatting.nixfmt,
-- null_ls.builtins.formatting.nixpkgs_fmt,
null_ls.builtins.formatting.shellharden,
null_ls.builtins.formatting.stylua,
null_ls.builtins.hover.dictionary,
}

View file

@ -9,7 +9,7 @@ return {
{ "L3MON4D3/LuaSnip", dependencies = { "hrsh7th/nvim-cmp", "saadparwaiz1/cmp_luasnip" } },
{ "windwp/nvim-autopairs", dependencies = { "hrsh7th/nvim-cmp" } },
{ "folke/neodev.nvim", dependencies = { "hrsh7th/nvim-cmp" } },
"jose-elias-alvarez/null-ls.nvim",
{ "jose-elias-alvarez/null-ls.nvim", dependencies = { "davidmh/cspell.nvim" } },
},
config = function()
require "lsp.config"