From 56156e1fe4c0b0b5c4254dfa71a6d0d0eb66beea Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Mar 2022 11:20:50 +0100 Subject: [PATCH] home: vim: do not use 'ftplugin' for 'null-ls' Unfortunately, this registers the sources many times... I fear that I will have to settle for a centralised configuration for LSP-related options. --- home/vim/after/ftplugin/bash.vim | 26 -------- home/vim/after/ftplugin/c.vim | 10 --- home/vim/after/ftplugin/cpp.vim | 10 --- home/vim/after/ftplugin/haskell.vim | 13 ---- home/vim/after/ftplugin/nix.vim | 15 ----- home/vim/after/ftplugin/python.vim | 36 ----------- home/vim/after/ftplugin/sh.vim | 26 -------- home/vim/after/ftplugin/zsh.vim | 26 -------- home/vim/plugin/settings/null-ls.vim | 96 ++++++++++++++++++++++++++++ 9 files changed, 96 insertions(+), 162 deletions(-) delete mode 100644 home/vim/after/ftplugin/bash.vim delete mode 100644 home/vim/after/ftplugin/c.vim delete mode 100644 home/vim/after/ftplugin/cpp.vim delete mode 100644 home/vim/after/ftplugin/nix.vim delete mode 100644 home/vim/after/ftplugin/python.vim delete mode 100644 home/vim/after/ftplugin/sh.vim delete mode 100644 home/vim/after/ftplugin/zsh.vim diff --git a/home/vim/after/ftplugin/bash.vim b/home/vim/after/ftplugin/bash.vim deleted file mode 100644 index f9ca5eb..0000000 --- a/home/vim/after/ftplugin/bash.vim +++ /dev/null @@ -1,26 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.diagnostics.shellcheck.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" }, - -- 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 - extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "bash" }, - -- Only used if available - condition = utils.is_executable_condition("shfmt"), - }), -}) -EOF diff --git a/home/vim/after/ftplugin/c.vim b/home/vim/after/ftplugin/c.vim deleted file mode 100644 index 7e5a367..0000000 --- a/home/vim/after/ftplugin/c.vim +++ /dev/null @@ -1,10 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -null_ls.register({ - null_ls.builtins.formatting.clang_format, -}) -EOF diff --git a/home/vim/after/ftplugin/cpp.vim b/home/vim/after/ftplugin/cpp.vim deleted file mode 100644 index 7e5a367..0000000 --- a/home/vim/after/ftplugin/cpp.vim +++ /dev/null @@ -1,10 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -null_ls.register({ - null_ls.builtins.formatting.clang_format, -}) -EOF diff --git a/home/vim/after/ftplugin/haskell.vim b/home/vim/after/ftplugin/haskell.vim index 89c82d2..978f346 100644 --- a/home/vim/after/ftplugin/haskell.vim +++ b/home/vim/after/ftplugin/haskell.vim @@ -1,19 +1,6 @@ " Create the `b:undo_ftplugin` variable if it doesn't exist call ftplugined#check_undo_ft() -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.formatting.brittany.with({ - -- Only used if available - condition = utils.is_executable_condition("brittany"), - }), -}) -EOF - " Use a small indentation value on Haskell files setlocal shiftwidth=2 let b:undo_ftplugin.='|setlocal shiftwidth<' diff --git a/home/vim/after/ftplugin/nix.vim b/home/vim/after/ftplugin/nix.vim deleted file mode 100644 index a7421df..0000000 --- a/home/vim/after/ftplugin/nix.vim +++ /dev/null @@ -1,15 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.formatting.nixpkgs_fmt.with({ - -- Only used if available - condition = utils.is_executable_condition("nixpkgs-fmt"), - }), -}) -EOF diff --git a/home/vim/after/ftplugin/python.vim b/home/vim/after/ftplugin/python.vim deleted file mode 100644 index 42ea653..0000000 --- a/home/vim/after/ftplugin/python.vim +++ /dev/null @@ -1,36 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.diagnostics.flake8.with({ - -- Only used if available - condition = utils.is_executable_condition("flake8"), - }), - null_ls.builtins.diagnostics.mypy.with({ - -- Only used if available - condition = utils.is_executable_condition("mypy"), - }), - null_ls.builtins.diagnostics.pylint.with({ - -- Only used if available - condition = utils.is_executable_condition("pylint"), - }) - null_ls.builtins.formatting.black.with({ - extra_args = { "--fast" }, - -- Only used if available - condition = utils.is_executable_condition("black"), - }), - null_ls.builtins.formatting.isort.with({ - -- Only used if available - condition = utils.is_executable_condition("isort"), - }), -}) -EOF - -" Change max length of a line to 88 for this buffer to match black's settings -setlocal colorcolumn=88 -let b:undo_ftplugin.='|setlocal colorcolumn<' diff --git a/home/vim/after/ftplugin/sh.vim b/home/vim/after/ftplugin/sh.vim deleted file mode 100644 index 0e7582f..0000000 --- a/home/vim/after/ftplugin/sh.vim +++ /dev/null @@ -1,26 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.diagnostics.shellcheck.with({ - -- Show error code in message - diagnostics_format = "[#{c}] #{m}", - -- Require explicit empty string test - extra_args = { "-o", "avoid-nullary-conditions" }, - -- 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 - extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "posix" }, - -- Only used if available - condition = utils.is_executable_condition("shfmt"), - }), -}) -EOF diff --git a/home/vim/after/ftplugin/zsh.vim b/home/vim/after/ftplugin/zsh.vim deleted file mode 100644 index f9ca5eb..0000000 --- a/home/vim/after/ftplugin/zsh.vim +++ /dev/null @@ -1,26 +0,0 @@ -" Create the `b:undo_ftplugin` variable if it doesn't exist -call ftplugined#check_undo_ft() - -" Set-up LSP, linters, formatters -lua << EOF -local null_ls = require("null-ls") -local utils = require("ambroisie.utils") - -null_ls.register({ - null_ls.builtins.diagnostics.shellcheck.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" }, - -- 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 - extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "bash" }, - -- Only used if available - condition = utils.is_executable_condition("shfmt"), - }), -}) -EOF diff --git a/home/vim/plugin/settings/null-ls.vim b/home/vim/plugin/settings/null-ls.vim index 5dbbd73..a3972a2 100644 --- a/home/vim/plugin/settings/null-ls.vim +++ b/home/vim/plugin/settings/null-ls.vim @@ -1,5 +1,7 @@ lua << EOF local null_ls = require("null-ls") +local utils = require("ambroisie.utils") + null_ls.setup({ on_attach = function(client) -- Format on save @@ -13,4 +15,98 @@ null_ls.setup({ end end, }) + +-- C, C++ +null_ls.register({ + null_ls.builtins.formatting.clang_format.with({ + -- Only used if available + condition = utils.is_executable_condition("clang-format"), + }), +}) + +-- Haskell +null_ls.register({ + null_ls.builtins.formatting.brittany.with({ + -- Only used if available + condition = utils.is_executable_condition("brittany"), + }), +}) + +-- Nix +null_ls.register({ + null_ls.builtins.formatting.nixpkgs_fmt.with({ + -- Only used if available + condition = utils.is_executable_condition("nixpkgs-fmt"), + }), +}) + +-- Python +null_ls.register({ + null_ls.builtins.diagnostics.flake8.with({ + -- Only used if available + condition = utils.is_executable_condition("flake8"), + }), + null_ls.builtins.diagnostics.mypy.with({ + -- Only used if available + condition = utils.is_executable_condition("mypy"), + }), + null_ls.builtins.diagnostics.pylint.with({ + -- Only used if available + condition = utils.is_executable_condition("pylint"), + }), + null_ls.builtins.formatting.black.with({ + extra_args = { "--fast" }, + -- Only used if available + condition = utils.is_executable_condition("black"), + }), + null_ls.builtins.formatting.isort.with({ + -- Only used if available + condition = utils.is_executable_condition("isort"), + }), +}) + + +-- Shell (non-POSIX) +null_ls.register({ + null_ls.builtins.diagnostics.shellcheck.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 + extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "bash" }, + -- Restrict to bash and zsh + filetypes = { "bash", "zsh" }, + -- Only used if available + condition = utils.is_executable_condition("shfmt"), + }), +}) + +-- Shell (POSIX) +null_ls.register({ + null_ls.builtins.diagnostics.shellcheck.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 + extra_args = { "-i", "4", "-s", "-ci", "-sr", "-ln", "posix" }, + -- Only used if available + condition = utils.is_executable_condition("shfmt"), + }), +}) EOF