-
-
Notifications
You must be signed in to change notification settings - Fork 904
/
Copy pathlsp-elixir.el
159 lines (131 loc) · 5.69 KB
/
lsp-elixir.el
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
;;; lsp-elixir.el --- description -*- lexical-binding: t; -*-
;; Copyright (C) 2020 emacs-lsp maintainers
;; Author: emacs-lsp maintainers
;; Keywords: lsp, elixir
;; 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 Clients for the Elixir Programming Language.
;;; Code:
(require 'lsp-mode)
(require 'ht)
(defcustom lsp-elixir-dialyzer-enabled t
"Run ElixirLS's rapid Dialyzer when code is saved."
:type 'boolean
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-dialyzer-warn-opts '()
"Dialyzer options to enable or disable warnings.
See Dialyzer's documentation for options. Note that the \"race_conditions\" option is unsupported"
:type '(repeat string)
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-dialyzer-format "dialyxir_long"
"Formatter to use for Dialyzer warnings."
:type 'string
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-mix-env "test"
"Mix environment to use for compilation."
:type 'string
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-mix-target nil
"Mix target to use for compilation (requires Elixir >= 1.8)."
:type 'string
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-project-dir nil
"Subdirectory containing Mix project if not in the project root.
If value is `\"\"` then defaults to the workspace rootUri."
:type 'string
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-fetch-deps t
"Automatically fetch project dependencies when compiling."
:type 'boolean
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-suggest-specs t
"Suggest @spec annotations inline using Dialyzer's inferred success typings (Requires Dialyzer)."
:type 'boolean
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defcustom lsp-elixir-signature-after-complete t
"Show signature help after confirming autocomplete."
:type 'boolean
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defgroup lsp-elixir nil
"LSP support for Elixir, using elixir-ls."
:group 'lsp-mode
:link '(url-link "https://github.com/elixir-lsp/elixir-ls"))
(defcustom lsp-clients-elixir-server-executable
(if (equal system-type 'windows-nt)
"language_server.bat"
"language_server.sh")
"The elixir-language-server executable to use.
Leave as just the executable name to use the default behavior of
finding the executable with `exec-path'."
:group 'lsp-elixir
:type 'file)
(defcustom lsp-elixir-enable-test-lenses t
"Suggest Tests."
:type 'boolean
:group 'lsp-elixir
:package-version '(lsp-mode . "7.1"))
(defun lsp-elixir--build-test-command (argument)
"Builds the test command from the ARGUMENT."
(let ((test-name (lsp-get argument :testName))
(module (lsp-get argument :module))
(describe (lsp-get argument :describe)))
(cond (module (concat "\"" "module:" module "\""))
((not test-name) (concat "\"" "describe:" describe "\""))
(describe (concat "\"" "test:test " describe " " test-name "\"" ))
(t (concat "\"" "test:test " test-name "\"" )))))
(lsp-defun lsp-elixir--run-test ((&Command :arguments?))
"Runs tests."
(let* ((argument (lsp-seq-first arguments?))
(file-path (lsp-get argument :filePath))
(test-command (lsp-elixir--build-test-command argument)))
(compile
(concat "cd " (lsp-workspace-root file-path) " && "
"mix test --exclude test --include " test-command " " file-path
" --no-color"))
file-path))
(lsp-register-custom-settings
'(("elixirLS.dialyzerEnabled" lsp-elixir-dialyzer-enabled t)
("elixirLS.dialyzerWarnOpts" lsp-elixir-dialyzer-warn-opts)
("elixirLS.dialyzerFormat" lsp-elixir-dialyzer-format)
("elixirLS.mixEnv" lsp-elixir-mix-env)
("elixirLS.mixTarget" lsp-elixir-mix-target)
("elixirLS.projectDir" lsp-elixir-project-dir)
("elixirLS.fetchDeps" lsp-elixir-fetch-deps t)
("elixirLS.suggestSpecs" lsp-elixir-suggest-specs t)
("elixirLS.signatureAfterComplete" lsp-elixir-signature-after-complete t)
("elixirLS.enableTestLenses" lsp-elixir-enable-test-lenses t)))
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection (lambda () `(,lsp-clients-elixir-server-executable)))
:major-modes '(elixir-mode)
:priority -1
:server-id 'elixir-ls
:action-handlers (ht ("elixir.lens.test.run" 'lsp-elixir--run-test))
:initialized-fn (lambda (workspace)
(with-lsp-workspace workspace
(lsp--set-configuration
(lsp-configuration-section "elixirLS")))
(puthash
"textDocumentSync"
(ht ("save" t)
("change" 2))
(lsp--workspace-server-capabilities workspace)))))
(provide 'lsp-elixir)
;;; lsp-elixir.el ends here