config

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

lsp-elm.el (4533B)


      1 ;;; lsp-elm.el --- Elm Client settings             -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2019 Daniel V
      4 
      5 ;; Author: Daniel V
      6 ;; Keywords: elm lsp
      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-elm client
     24 
     25 ;;; Code:
     26 
     27 (require 'lsp-mode)
     28 
     29 (defgroup lsp-elm nil
     30   "LSP support for the Elm programming language, using the server from https://github.com/elm-tooling/elm-language-server"
     31   :group 'lsp-mode
     32   :link '(url-link "https://github.com/elm-tooling/elm-language-server"))
     33 
     34 (defcustom lsp-elm-elm-language-server-path nil
     35   "Path for elm-language-server.
     36 Can be installed globally with: npm i -g @elm-tooling/elm-language-server,
     37 or manually by cloning the repo and following the installing instructions."
     38   :group 'lsp-elm
     39   :risky t
     40   :type 'file)
     41 
     42 (defcustom lsp-elm-trace-server
     43   nil
     44   "Enable/disable trace logging of client and server communication."
     45   :type 'boolean
     46   :group 'lsp-elm)
     47 
     48 (defcustom lsp-elm-elm-path
     49   ""
     50   "The path to your elm executable.
     51 
     52 Should be empty by default, in that case it will assume the name and try
     53 to first get it from a local npm installation or a global one.  If you
     54 set it manually it will not try to load from the npm folder."
     55   :type 'file
     56   :group 'lsp-elm)
     57 
     58 (defcustom lsp-elm-elm-format-path
     59   ""
     60   "The path to your elm-format executable.
     61 
     62 Should be empty by default, in that case it will assume the name and try
     63 to first get it from a local npm installation or a global one.  If you
     64 set it manually it will not try to load from the npm folder."
     65   :type 'file
     66   :group 'lsp-elm)
     67 
     68 (defcustom lsp-elm-elm-test-path
     69   ""
     70   "The path to your elm-test executable.
     71 
     72 Should be empty by default, in that case it will assume the name and try
     73 to first get it from a local npm installation or a global one.  If you
     74 set it manually it will not try to load from the npm folder."
     75   :type 'file
     76   :group 'lsp-elm)
     77 
     78 (defcustom lsp-elm-disable-elmls-diagnostics
     79   nil
     80   "Enable/Disable linting diagnostics from the language server."
     81   :type 'boolean
     82   :group 'lsp-elm)
     83 
     84 (defcustom lsp-elm-only-update-diagnostics-on-save
     85   nil
     86   "Only update compiler diagnostics on save, not on document change."
     87   :type 'boolean
     88   :group 'lsp-elm)
     89 
     90 (defcustom lsp-elm-skip-install-package-confirmation
     91   nil
     92   "Skip confirmation for the Install Package code action."
     93   :type 'boolean
     94   :group 'lsp-elm)
     95 
     96 (defcustom lsp-elm-server-args
     97   '("--stdio")
     98   "Arguments to pass to the server."
     99   :type '(repeat string)
    100   :group 'lsp-elm)
    101 
    102 (defun lsp-elm--elm-language-server-command ()
    103   "Generate LSP startup command for the Elm Language Server."
    104   (cons
    105    (or lsp-elm-elm-language-server-path
    106        (lsp-package-path 'elm-language-server))
    107    lsp-elm-server-args))
    108 
    109 (defun lsp-clients-elm--make-init-options ()
    110   "Init options for elm-language-server."
    111   `(:elmPath ,lsp-elm-elm-path
    112     :elmFormatPath ,lsp-elm-elm-format-path
    113     :elmTestPath ,lsp-elm-elm-test-path
    114     :disableElmLSDiagnostics ,(lsp-json-bool lsp-elm-disable-elmls-diagnostics)
    115     :onlyUpdateDiagnosticsOnSave ,(lsp-json-bool lsp-elm-only-update-diagnostics-on-save)
    116     :skipInstallPackageConfirmation ,(lsp-json-bool lsp-elm-skip-install-package-confirmation)
    117     :trace.server ,(lsp-json-bool lsp-elm-trace-server)))
    118 
    119 (lsp-dependency 'elm-language-server
    120                 '(:system "elm-language-server")
    121                 '(:npm :package "@elm-tooling/elm-language-server"
    122                        :path "elm-language-server"))
    123 
    124 (lsp-register-client
    125  (make-lsp-client
    126   :new-connection (lsp-stdio-connection #'lsp-elm--elm-language-server-command)
    127   :major-modes '(elm-mode)
    128   :priority -1
    129   :initialization-options #'lsp-clients-elm--make-init-options
    130   :server-id 'elm-ls
    131   :download-server-fn (lambda (_client callback error-callback _update?)
    132                         (lsp-package-ensure 'elm-language-server callback error-callback))))
    133 
    134 (lsp-consistency-check lsp-elm)
    135 
    136 (provide 'lsp-elm)
    137 ;;; lsp-elm.el ends here