home: vim: lspconfig: migrate to 'bashls'

Since `none-ls` has removed their `shellcheck` built-in. This actually
makes the diagnostics more robust to POSIX/non-POSIX scripts (the LSP
server detects it at runtime, which is more robust than the `ftdetect`
scripts).

Nice bonus: the shellcheck code is shown in the diagnostics message
without any configuration!

I'm not sure if I can configure `avoid-nullary-conditions` -- though it
seems like this check is broken at the moment (I couldn't get it to
trigger during my tests).
This commit is contained in:
Bruno BELANYI 2024-03-11 12:20:53 +00:00
parent 7a3e64f814
commit dc27b59912
3 changed files with 10 additions and 34 deletions

View file

@ -68,7 +68,6 @@ in
lsp-format-nvim # Simplified formatting configuration
lsp_lines-nvim # Show diagnostics *over* regions
none-ls-nvim # LSP integration for linters and formatters
none-ls-shellcheck-nvim # shellcheck shim for none-ls
nvim-treesitter.withAllGrammars # Better highlighting
nvim-treesitter-textobjects # More textobjects
nvim-ts-context-commentstring # Comment string in nested language blocks
@ -106,7 +105,7 @@ in
nixpkgs-fmt
# Shell
shellcheck
nodePackages.bash-language-server
shfmt
];
};

View file

@ -74,3 +74,12 @@ if utils.is_executable("rust-analyzer") then
on_attach = lsp.on_attach,
})
end
-- Shell
if utils.is_executable("bash-language-server") then
lspconfig.bashls.setup({
filetypes = { "bash", "sh", "zsh" },
capabilities = capabilities,
on_attach = lsp.on_attach,
})
end

View file

@ -63,22 +63,6 @@ null_ls.register({
-- Shell (non-POSIX)
null_ls.register({
require("none-ls-shellcheck.diagnostics").with({
-- Restrict to bash and zsh
filetypes = { "bash", "zsh" },
-- Only used if available
condition = utils.is_executable_condition("shellcheck"),
}),
require("none-ls-shellcheck.code_actions").with({
-- Show error code in message
diagnostics_format = "[#{c}] #{m}",
-- Require explicit empty string test, use bash dialect
extra_args = { "-s", "bash", "-o", "avoid-nullary-conditions" },
-- Restrict to bash and zsh
filetypes = { "bash", "zsh" },
-- Only used if available
condition = utils.is_executable_condition("shellcheck"),
}),
null_ls.builtins.formatting.shfmt.with({
-- Indent with 4 spaces, simplify the code, indent switch cases,
-- add space after redirection, use bash dialect
@ -92,22 +76,6 @@ null_ls.register({
-- Shell (POSIX)
null_ls.register({
require("none-ls-shellcheck.diagnostics").with({
-- Restrict to POSIX sh
filetypes = { "sh" },
-- Only used if available
condition = utils.is_executable_condition("shellcheck"),
}),
require("none-ls-shellcheck.code_actions").with({
-- Show error code in message
diagnostics_format = "[#{c}] #{m}",
-- Require explicit empty string test
extra_args = { "-o", "avoid-nullary-conditions" },
-- Restrict to POSIX sh
filetypes = { "sh" },
-- Only used if available
condition = utils.is_executable_condition("shellcheck"),
}),
null_ls.builtins.formatting.shfmt.with({
-- Indent with 4 spaces, simplify the code, indent switch cases,
-- add space after redirection, use POSIX