From cb719af306a5760ffd82e99f7b829a05edf8c51d Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 27 Apr 2022 02:28:24 +0100 Subject: [PATCH] feat(languages): enable shellcheck linting when using bash language server Due to how lsp integrates with flycheck, it needs to take over all linting responsibilities. Hence we need to use efm-langserver to execute shellcheck for us. It's a bit messy, but end result works pretty well. --- modules/languages/siren-sh.el | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/languages/siren-sh.el b/modules/languages/siren-sh.el index 8e6ffdb..4cb3c28 100644 --- a/modules/languages/siren-sh.el +++ b/modules/languages/siren-sh.el @@ -51,7 +51,34 @@ :preface (defun siren-lsp-bash-mode-setup () (if (member sh-shell '(bash sh)) - (lsp-deferred)))) + (lsp-deferred))) + + :config + ;; Create custom lsp-client for shellcheck diagnostics via efm-langserver. + (when (and (executable-find "efm-langserver") + (executable-find "shellcheck")) + (lsp-register-custom-settings + '(("shellcheck.rootMarkers" [".git/"]) + ("shellcheck.languages" + ((shellscript . [((lintCommand . "shellcheck -f gcc -x -") + (lintStdin . t) + (lintSource . "shellcheck") + (lintFormats . ["%f:%l:%c: %trror: %m" + "%f:%l:%c: %tarning: %m" + "%f:%l:%c: %tote: %m"]))]))))) + (lsp-register-client + (make-lsp-client :new-connection (lsp-stdio-connection + '("efm-langserver")) + :priority 0 + :activation-fn #'lsp-bash-check-sh-shell + :initialized-fn + (lambda (workspace) + (with-lsp-workspace workspace + (lsp--set-configuration + (gethash "shellcheck" + (lsp-configuration-section "shellcheck"))))) + :server-id 'shellcheck + :add-on? t)))) (use-package shfmt :hook