config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

lsp-bash.el (3186B)


      1 ;;; lsp-bash.el --- description -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2020 emacs-lsp maintainers
      4 
      5 ;; Author: emacs-lsp maintainers
      6 ;; Keywords: lsp, bash, shell-script
      7 
      8 ;; This program is free software; you can redistribute it and/or modify
      9 ;; it under the terms of the GNU General Public License as published by
     10 ;; the Free Software Foundation, either version 3 of the License, or
     11 ;; (at your option) any later version.
     12 
     13 ;; This program is distributed in the hope that it will be useful,
     14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;; GNU General Public License for more details.
     17 
     18 ;; You should have received a copy of the GNU General Public License
     19 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     20 
     21 ;;; Commentary:
     22 
     23 ;; LSP Clients for the Bash Programming Language
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 ;;; Bash
     30 (defgroup lsp-bash nil
     31   "Settings for the Bash Language Server."
     32   :group 'lsp-mode
     33   :link '(url-link "https://github.com/bash-lsp/bash-language-server")
     34   :package-version '(lsp-mode . "6.2"))
     35 
     36 (defcustom lsp-bash-explainshell-endpoint nil
     37   "The endpoint to use explainshell.com to answer `onHover' queries.
     38 See instructions at https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode"
     39   :type 'string
     40   :risky t
     41   :group 'lsp-bash
     42   :package-version '(lsp-mode . "6.2"))
     43 
     44 (defcustom lsp-bash-highlight-parsing-errors nil
     45   "Consider parsing errors in scripts as `problems'."
     46   :type 'boolean
     47   :group 'lsp-bash
     48   :package-version '(lsp-mode . "6.2"))
     49 
     50 (defcustom lsp-bash-glob-pattern nil
     51   "Glob pattern used to find shell script files to parse."
     52   :type 'string
     53   :group 'lsp-bash
     54   :package-version '(lsp-mode . "6.3"))
     55 
     56 (defun lsp-bash--bash-ls-server-command ()
     57   "Startup command for Bash language server."
     58   (list (lsp-package-path 'bash-language-server) "start"))
     59 
     60 (lsp-dependency 'bash-language-server
     61                 '(:system "bash-language-server")
     62                 '(:npm :package "bash-language-server"
     63                        :path "bash-language-server"))
     64 
     65 (defvar sh-shell)
     66 
     67 (defun lsp-bash-check-sh-shell (&rest _)
     68   "Check whether `sh-shell' is sh or bash.
     69 
     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))))
     73 
     74 (lsp-register-client
     75  (make-lsp-client
     76   :new-connection (lsp-stdio-connection #'lsp-bash--bash-ls-server-command)
     77   :major-modes '(sh-mode bash-ts-mode ebuild-mode envrc-file-mode)
     78   :priority -1
     79   :activation-fn #'lsp-bash-check-sh-shell
     80   :environment-fn (lambda ()
     81                     '(("EXPLAINSHELL_ENDPOINT" . lsp-bash-explainshell-endpoint)
     82                       ("HIGHLIGHT_PARSING_ERRORS" . lsp-bash-highlight-parsing-errors)
     83                       ("GLOB_PATTERN" . lsp-bash-glob-pattern)))
     84   :server-id 'bash-ls
     85   :download-server-fn (lambda (_client callback error-callback _update?)
     86                         (lsp-package-ensure 'bash-language-server callback error-callback))))
     87 
     88 (lsp-consistency-check lsp-bash)
     89 
     90 (provide 'lsp-bash)
     91 ;;; lsp-bash.el ends here