From 723a59602ba8af61b0efc3c31d35bb65b6c1c63b Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Fri, 22 Nov 2024 09:29:40 +0000 Subject: [PATCH 1/4] lsp-bash: Remove major mode duplication These are already filtered by `:major-modes` so there's no need to filter them again in the `:activation-fn`. `:major-modes` was originally removed in: - b77aecf2d613c7ed5cadb9c5c37fcbb205c3f3a9 But then reintroduced in: - 771342f03986fe8d77696ae9b08e72741006843e --- clients/lsp-bash.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clients/lsp-bash.el b/clients/lsp-bash.el index ff5aa86babb..97005826ae2 100644 --- a/clients/lsp-bash.el +++ b/clients/lsp-bash.el @@ -68,8 +68,7 @@ See instructions at https://marketplace.visualstudio.com/items?itemName=mads-har "Check whether `sh-shell' is sh or bash. This prevents the Bash server from being turned on in zsh files." - (and (memq major-mode '(sh-mode bash-ts-mode ebuild-mode envrc-file-mode)) - (memq sh-shell '(sh bash)))) + (memq sh-shell '(sh bash))) (lsp-register-client (make-lsp-client From 9c0f70b16116d8fb96119929da7c7461c710e686 Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Fri, 22 Nov 2024 12:05:14 +0000 Subject: [PATCH 2/4] lsp-bash: Expose lsp-bash-allowed-shells Make the `sh-shell` values that are filtered by `:activation-fn` configurable without needing to override `lsp-bash-check-sh-shell` This allows people to allow values like `bats` and also makes it slightly clearer why those values aren't supported by default when the major mode is, which took me a long time to debug. --- CHANGELOG.org | 1 + clients/lsp-bash.el | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 514fdb9b92e..e7ed1a7bba2 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -24,6 +24,7 @@ * Add fennel support * Add support for [[https://github.com/nextflow-io/language-server][Nextflow]] * Add TypeSpec support + * Add ~lsp-bash-allowed-shells~ to configure supported ~sh-shell~ values. ** 9.0.0 * Add language server config for QML (Qt Modeling Language) using qmlls. diff --git a/clients/lsp-bash.el b/clients/lsp-bash.el index 97005826ae2..1b66c34cdb3 100644 --- a/clients/lsp-bash.el +++ b/clients/lsp-bash.el @@ -33,6 +33,12 @@ :link '(url-link "https://github.com/bash-lsp/bash-language-server") :package-version '(lsp-mode . "6.2")) +(defcustom lsp-bash-allowed-shells '(sh bash) + "List of allowed `sh-shell` values that LSP will be enabled for." + :type '(list symbol) + :group 'lsp-bash + :package-version '(lsp-mode . "9.0.1")) + (defcustom lsp-bash-explainshell-endpoint nil "The endpoint to use explainshell.com to answer `onHover' queries. See instructions at https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode" @@ -65,10 +71,10 @@ See instructions at https://marketplace.visualstudio.com/items?itemName=mads-har (defvar sh-shell) (defun lsp-bash-check-sh-shell (&rest _) - "Check whether `sh-shell' is sh or bash. + "Check whether `sh-shell' is supported. -This prevents the Bash server from being turned on in zsh files." - (memq sh-shell '(sh bash))) +This prevents the Bash server from being turned on for unsupported dialects, e.g. `zsh`." + (memq sh-shell lsp-bash-allowed-shells)) (lsp-register-client (make-lsp-client From f650409323ff3782b3260d6deb6f1baba590df5d Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Fri, 22 Nov 2024 12:05:26 +0000 Subject: [PATCH 3/4] lsp-mode: Improve warning about :activation-fn To make it easier to debug situations where the `:major-mode` is supported but `:activation-fn` prevents the buffer from being supported for other reasons, such as `lsp-bash` rejecting an `sh-shell` value of `bats`. --- CHANGELOG.org | 1 + lsp-mode.el | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index e7ed1a7bba2..0e58903b2c5 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -25,6 +25,7 @@ * Add support for [[https://github.com/nextflow-io/language-server][Nextflow]] * Add TypeSpec support * Add ~lsp-bash-allowed-shells~ to configure supported ~sh-shell~ values. + * Add hint about ~activation-fn~ for unsupported buffers. ** 9.0.0 * Add language server config for QML (Qt Modeling Language) using qmlls. diff --git a/lsp-mode.el b/lsp-mode.el index 5f81502ec9b..2653cd84b3a 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -9454,9 +9454,10 @@ You may find the installation instructions at https://emacs-lsp.github.io/lsp-mo This issue might be caused by: 1. The language you are trying to use does not have built-in support in `lsp-mode'. You must install the required support manually. Examples of this are `lsp-java' or `lsp-metals'. 2. The language server that you expect to run is not configured to run for major mode `%s'. You may check that by checking the `:major-modes' that are passed to `lsp-register-client'. -3. `lsp-mode' doesn't have any integration for the language behind `%s'. Refer to https://emacs-lsp.github.io/lsp-mode/page/languages and https://langserver.org/ . -4. You are over `tramp'. In this case follow https://emacs-lsp.github.io/lsp-mode/page/remote/. -5. You have disabled the `lsp-mode' clients for that file. (Check `lsp-enabled-clients' and `lsp-disabled-clients'). +3. The language server that you expect to run has an `:activation-fn` passed to `lsp-register-client` that prevents it supporting this buffer. +4. `lsp-mode' doesn't have any integration for the language behind `%s'. Refer to https://emacs-lsp.github.io/lsp-mode/page/languages and https://langserver.org/ . +5. You are over `tramp'. In this case follow https://emacs-lsp.github.io/lsp-mode/page/remote/. +6. You have disabled the `lsp-mode' clients for that file. (Check `lsp-enabled-clients' and `lsp-disabled-clients'). You can customize `lsp-warn-no-matched-clients' to disable this message." major-mode major-mode major-mode)))))) From 2b3219de224411f4f42c729e1c8434e72b56f0a5 Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Mon, 25 Nov 2024 11:05:52 +0000 Subject: [PATCH 4/4] lsp-bash: Fix for unbound sh-shell Fix the following test: Test lsp-mock-doc-changes-wrong-version condition: (void-variable sh-shell) By only checking `lsp-bash-allowed-shells` when `sh-shell` is bound to a value. For reasons that I'm not entirely clear about, this was fine previously when checking against a static list. --- clients/lsp-bash.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clients/lsp-bash.el b/clients/lsp-bash.el index 1b66c34cdb3..571c90fb63d 100644 --- a/clients/lsp-bash.el +++ b/clients/lsp-bash.el @@ -74,7 +74,8 @@ See instructions at https://marketplace.visualstudio.com/items?itemName=mads-har "Check whether `sh-shell' is supported. This prevents the Bash server from being turned on for unsupported dialects, e.g. `zsh`." - (memq sh-shell lsp-bash-allowed-shells)) + (and (boundp 'sh-shell) + (memq sh-shell lsp-bash-allowed-shells))) (lsp-register-client (make-lsp-client