From f551c4fc302abf9416b629c8f6f0ad7598367908 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 28 Feb 2022 11:31:26 +0100 Subject: [PATCH] home: vim: only use 'null-ls' sources if available This avoids the big red warning on each file that tries to use those sources... --- home/vim/after/ftplugin/bash.vim | 6 ++++++ home/vim/after/ftplugin/haskell.vim | 7 ++++++- home/vim/after/ftplugin/nix.vim | 7 ++++++- home/vim/after/ftplugin/python.vim | 24 ++++++++++++++++++++---- home/vim/after/ftplugin/sh.vim | 6 ++++++ home/vim/after/ftplugin/zsh.vim | 6 ++++++ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/home/vim/after/ftplugin/bash.vim b/home/vim/after/ftplugin/bash.vim index cb85c8f..f9ca5eb 100644 --- a/home/vim/after/ftplugin/bash.vim +++ b/home/vim/after/ftplugin/bash.vim @@ -4,17 +4,23 @@ 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/haskell.vim b/home/vim/after/ftplugin/haskell.vim index 776adbe..89c82d2 100644 --- a/home/vim/after/ftplugin/haskell.vim +++ b/home/vim/after/ftplugin/haskell.vim @@ -4,8 +4,13 @@ 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, + null_ls.builtins.formatting.brittany.with({ + -- Only used if available + condition = utils.is_executable_condition("brittany"), + }), }) EOF diff --git a/home/vim/after/ftplugin/nix.vim b/home/vim/after/ftplugin/nix.vim index a5056c8..a7421df 100644 --- a/home/vim/after/ftplugin/nix.vim +++ b/home/vim/after/ftplugin/nix.vim @@ -4,7 +4,12 @@ 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, + 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 index ffc0327..42ea653 100644 --- a/home/vim/after/ftplugin/python.vim +++ b/home/vim/after/ftplugin/python.vim @@ -4,14 +4,30 @@ 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, - null_ls.builtins.diagnostics.mypy, - null_ls.builtins.diagnostics.pylint, + 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"), }), - null_ls.builtins.formatting.isort, }) EOF diff --git a/home/vim/after/ftplugin/sh.vim b/home/vim/after/ftplugin/sh.vim index 442ebcb..0e7582f 100644 --- a/home/vim/after/ftplugin/sh.vim +++ b/home/vim/after/ftplugin/sh.vim @@ -4,17 +4,23 @@ 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 index cb85c8f..f9ca5eb 100644 --- a/home/vim/after/ftplugin/zsh.vim +++ b/home/vim/after/ftplugin/zsh.vim @@ -4,17 +4,23 @@ 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