aboutsummaryrefslogtreecommitdiffstats
path: root/elpa/lsp-mode-20220505.630/lsp-elm.el
blob: 55f9f279546838b703bf078e8fbb5ddd7efd3af2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; lsp-elm.el --- Elm Client settings             -*- lexical-binding: t; -*-

;; Copyright (C) 2019 Daniel V

;; Author: Daniel V
;; Keywords: elm lsp

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; lsp-elm client

;;; Code:

(require 'lsp-mode)

(defgroup lsp-elm nil
  "LSP support for the Elm programming language, using the server from https://github.com/elm-tooling/elm-language-server"
  :group 'lsp-mode
  :link '(url-link "https://github.com/elm-tooling/elm-language-server"))

(defcustom lsp-elm-elm-language-server-path nil
  "Path for elm-language-server.
Can be installed globally with: npm i -g @elm-tooling/elm-language-server,
or manually by cloning the repo and following the installing instructions."
  :group 'lsp-elm
  :risky t
  :type 'file)

(defcustom lsp-elm-trace-server
  nil
  "Enable/disable trace logging of client and server communication."
  :type 'boolean
  :group 'lsp-elm)

(defcustom lsp-elm-elm-path
  ""
  "The path to your elm executable.

Should be empty by default, in that case it will assume the name and try
to first get it from a local npm installation or a global one.  If you
set it manually it will not try to load from the npm folder."
  :type 'file
  :group 'lsp-elm)

(defcustom lsp-elm-elm-format-path
  ""
  "The path to your elm-format executable.

Should be empty by default, in that case it will assume the name and try
to first get it from a local npm installation or a global one.  If you
set it manually it will not try to load from the npm folder."
  :type 'file
  :group 'lsp-elm)

(defcustom lsp-elm-elm-test-path
  ""
  "The path to your elm-test executable.

Should be empty by default, in that case it will assume the name and try
to first get it from a local npm installation or a global one.  If you
set it manually it will not try to load from the npm folder."
  :type 'file
  :group 'lsp-elm)

(defcustom lsp-elm-disable-elmls-diagnostics
  nil
  "Enable/Disable linting diagnostics from the language server."
  :type 'boolean
  :group 'lsp-elm)

(defcustom lsp-elm-only-update-diagnostics-on-save
  nil
  "Only update compiler diagnostics on save, not on document change."
  :type 'boolean
  :group 'lsp-elm)

(defcustom lsp-elm-skip-install-package-confirmation
  nil
  "Skip confirmation for the Install Package code action."
  :type 'boolean
  :group 'lsp-elm)

(defcustom lsp-elm-server-args
  '("--stdio")
  "Arguments to pass to the server."
  :type '(repeat string)
  :group 'lsp-elm)

(defun lsp-elm--elm-language-server-command ()
  "Generate LSP startup command for the Elm Language Server."
  (cons
   (or lsp-elm-elm-language-server-path
       (lsp-package-path 'elm-language-server))
   lsp-elm-server-args))

(defun lsp-clients-elm--make-init-options ()
  "Init options for elm-language-server."
  `(:elmPath ,lsp-elm-elm-path
    :elmFormatPath ,lsp-elm-elm-format-path
    :elmTestPath ,lsp-elm-elm-test-path
    :disableElmLSDiagnostics ,(lsp-json-bool lsp-elm-disable-elmls-diagnostics)
    :onlyUpdateDiagnosticsOnSave ,(lsp-json-bool lsp-elm-only-update-diagnostics-on-save)
    :skipInstallPackageConfirmation ,(lsp-json-bool lsp-elm-skip-install-package-confirmation)
    :trace.server ,(lsp-json-bool lsp-elm-trace-server)))

(lsp-dependency 'elm-language-server
                '(:system "elm-language-server")
                '(:npm :package "@elm-tooling/elm-language-server"
                       :path "elm-language-server"))

(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection #'lsp-elm--elm-language-server-command)
  :major-modes '(elm-mode)
  :priority -1
  :initialization-options #'lsp-clients-elm--make-init-options
  :server-id 'elm-ls
  :download-server-fn (lambda (_client callback error-callback _update?)
                        (lsp-package-ensure 'elm-language-server callback error-callback))))

(lsp-consistency-check lsp-elm)

(provide 'lsp-elm)
;;; lsp-elm.el ends here