Skip to content

Commit 4a65b4b

Browse files
dcarleyjcs090218
andauthored
Expose lsp-bash-allowed-shell and improve warning (#4620)
* 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: - b77aecf But then reintroduced in: - 771342f * 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. * 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`. * 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. --------- Co-authored-by: Jen-Chieh Shen <jcs090218@gmail.com>
1 parent 7abfcc2 commit 4a65b4b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CHANGELOG.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* Add TypeSpec support
2727
* Add Tree-sitter query support
2828
* Add [[https://github.com/mrjosh/helm-ls][helm-ls]] (YAML Kubernetes Helm) support.
29+
* Add ~lsp-bash-allowed-shells~ to configure supported ~sh-shell~ values.
30+
* Add hint about ~activation-fn~ for unsupported buffers.
2931

3032
** 9.0.0
3133
* Add language server config for QML (Qt Modeling Language) using qmlls.

clients/lsp-bash.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
:link '(url-link "https://github.com/bash-lsp/bash-language-server")
3434
:package-version '(lsp-mode . "6.2"))
3535

36+
(defcustom lsp-bash-allowed-shells '(sh bash)
37+
"List of allowed `sh-shell` values that LSP will be enabled for."
38+
:type '(list symbol)
39+
:group 'lsp-bash
40+
:package-version '(lsp-mode . "9.0.1"))
41+
3642
(defcustom lsp-bash-explainshell-endpoint nil
3743
"The endpoint to use explainshell.com to answer `onHover' queries.
3844
See instructions at https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode"
@@ -65,11 +71,11 @@ See instructions at https://marketplace.visualstudio.com/items?itemName=mads-har
6571
(defvar sh-shell)
6672

6773
(defun lsp-bash-check-sh-shell (&rest _)
68-
"Check whether `sh-shell' is sh or bash.
74+
"Check whether `sh-shell' is supported.
6975
70-
This prevents the Bash server from being turned on in zsh files."
71-
(and (memq major-mode '(sh-mode bash-ts-mode ebuild-mode envrc-file-mode))
72-
(memq sh-shell '(sh bash))))
76+
This prevents the Bash server from being turned on for unsupported dialects, e.g. `zsh`."
77+
(and (boundp 'sh-shell)
78+
(memq sh-shell lsp-bash-allowed-shells)))
7379

7480
(lsp-register-client
7581
(make-lsp-client

lsp-mode.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9495,9 +9495,10 @@ You may find the installation instructions at https://emacs-lsp.github.io/lsp-mo
94959495
This issue might be caused by:
94969496
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'.
94979497
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'.
9498-
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/ .
9499-
4. You are over `tramp'. In this case follow https://emacs-lsp.github.io/lsp-mode/page/remote/.
9500-
5. You have disabled the `lsp-mode' clients for that file. (Check `lsp-enabled-clients' and `lsp-disabled-clients').
9498+
3. The language server that you expect to run has an `:activation-fn` passed to `lsp-register-client` that prevents it supporting this buffer.
9499+
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/ .
9500+
5. You are over `tramp'. In this case follow https://emacs-lsp.github.io/lsp-mode/page/remote/.
9501+
6. You have disabled the `lsp-mode' clients for that file. (Check `lsp-enabled-clients' and `lsp-disabled-clients').
95019502
You can customize `lsp-warn-no-matched-clients' to disable this message."
95029503
major-mode major-mode major-mode))))))
95039504

0 commit comments

Comments
 (0)