From 724eb908a8a2a40e843e4d8bf1aef5f28ba6d0ab Mon Sep 17 00:00:00 2001 From: Daniel Richtmann Date: Thu, 3 Jan 2019 11:53:34 +0100 Subject: [PATCH] Enable experimental support for lsp within the shell-scripts layer Note that this is only valid for bash scripts, since it uses the `bash-language-server` defined in `lsp-clients.el` --- CHANGELOG.develop | 2 ++ layers/+lang/shell-scripts/README.org | 26 ++++++++++++++++++++++++++ layers/+lang/shell-scripts/config.el | 3 +++ layers/+lang/shell-scripts/funcs.el | 14 ++++++++++++++ layers/+lang/shell-scripts/packages.el | 3 ++- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 5be351661..cab55511d 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -2567,6 +2567,8 @@ Other: - Added insert commands from sh-script package to major mode menu (thanks to Maximilian Wolff) - Added org-mode support (thanks to Josh Santos) +- Added LSP support, which can be used by enabling the =lsp= layer and setting + the =shell-scripts= layer's =shell-scripts-backend= variable to =lsp= **** Slack - New layer variable =slack-spacemacs-layout-name= to customize the name of the custom layer for Slack buffers (thanks to Benjamin Reynolds) diff --git a/layers/+lang/shell-scripts/README.org b/layers/+lang/shell-scripts/README.org index 62b37a876..020fd7c6c 100644 --- a/layers/+lang/shell-scripts/README.org +++ b/layers/+lang/shell-scripts/README.org @@ -8,8 +8,12 @@ - [[#description][Description]] - [[#features][Features:]] - [[#install][Install]] + - [[#layer][Layer]] - [[#linting][Linting]] - [[#style-checking][Style checking]] + - [[#setting-the-backend][Setting the backend]] +- [[#backend][Backend]] + - [[#language-server-protocol][Language Server Protocol]] - [[#key-bindings][Key bindings]] * Description @@ -25,8 +29,10 @@ Supported scripting files: - Auto-completion using [[https://github.com/Alexander-Miller/company-shell][company-shell]] - =Sh= scripts linting using [[https://www.shellcheck.net/][shellcheck]] - =Sh= scripts style checking using [[https://github.com/openstack-dev/bashate][bashate]] +- Support for the [[https://langserver.org/][Language Server Protocol]] (experimental) * Install +** Layer To use this configuration layer, add it to your =~/.spacemacs=. You will need to add =shell-scripts= to the existing =dotspacemacs-configuration-layers= list in this file. @@ -37,6 +43,26 @@ In order to enable =sh= scripts linting, install [[https://www.shellcheck.net/][ ** Style checking In order to enable =sh= scripts style checking, install [[https://github.com/openstack-dev/bashate][bashate]]. +** Setting the backend +To activate the backend set the layer variable =shell-scripts-backend=: + +#+BEGIN_SRC elisp + (shell-scripts :variables shell-scripts-backend 'lsp) +#+END_SRC + +For spacemacs to use lsp you also need to add =lsp= to the +=dotspacemacs-configuration-layers= in your =~/.spacemacs= file. + +* Backend +** Language Server Protocol +You have to install the bash language server: + +#+BEGIN_SRC sh + npm i -g bash-language-server +#+END_SRC + +You can find further information on the project's [[https://github.com/mads-hartmann/bash-language-server][GitHub page]]. + * Key bindings | Key binding | Description | diff --git a/layers/+lang/shell-scripts/config.el b/layers/+lang/shell-scripts/config.el index 26f43b781..3f33ff464 100644 --- a/layers/+lang/shell-scripts/config.el +++ b/layers/+lang/shell-scripts/config.el @@ -12,3 +12,6 @@ ;; variables (spacemacs|define-jump-handlers sh-mode) + +(defvar shell-scripts-backend nil + "The backend to use for IDE features. Possible values are `lsp'.") diff --git a/layers/+lang/shell-scripts/funcs.el b/layers/+lang/shell-scripts/funcs.el index 430c020de..d7c0f3bea 100644 --- a/layers/+lang/shell-scripts/funcs.el +++ b/layers/+lang/shell-scripts/funcs.el @@ -18,3 +18,17 @@ (require 'insert-shebang) (insert-shebang-get-extension-and-insert (file-name-nondirectory (buffer-file-name)))) + + +;; lsp + +(defun spacemacs//shell-scripts-setup-backend () + "Conditionally setup shell-scripts backend." + (pcase shell-scripts-backend + (`lsp (spacemacs//shell-scripts-setup-lsp)))) + +(defun spacemacs//shell-scripts-setup-lsp () + "Setup lsp backend." + (if (configuration-layer/layer-used-p 'lsp) + (lsp) + (message "`lsp' layer is not installed, please add `lsp' layer to your dotfile."))) diff --git a/layers/+lang/shell-scripts/packages.el b/layers/+lang/shell-scripts/packages.el index 1a496ae60..f4edce531 100644 --- a/layers/+lang/shell-scripts/packages.el +++ b/layers/+lang/shell-scripts/packages.el @@ -84,7 +84,8 @@ (when (and buffer-file-name (string-match-p "\\.zsh\\'" buffer-file-name)) (sh-set-shell "zsh"))) - (add-hook 'sh-mode-hook 'spacemacs//setup-shell)))) + (add-hook 'sh-mode-hook 'spacemacs//setup-shell) + (add-hook 'sh-mode-hook 'spacemacs//shell-scripts-setup-backend)))) (defun shell-scripts/post-init-ggtags () (add-hook 'sh-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))