@@ -100,6 +100,33 @@ finding the executable with `exec-path'."
100
100
:group 'lsp-elixir
101
101
:type 'file )
102
102
103
+ (defcustom lsp-elixir-enable-test-lenses t
104
+ " Suggest Tests."
105
+ :type 'boolean
106
+ :group 'lsp-elixir
107
+ :package-version '(lsp-mode . " 7.1" ))
108
+
109
+ (defun lsp-elixir--build-test-command (argument )
110
+ " Builds the test command from the ARGUMENT."
111
+ (let ((test-name (lsp-get argument :testName ))
112
+ (module (lsp-get argument :module ))
113
+ (describe (lsp-get argument :describe )))
114
+ (cond (module (concat " \" " " module:" module " \" " ))
115
+ ((not test-name) (concat " \" " " describe:" describe " \" " ))
116
+ (describe (concat " \" " " test:test " describe " " test-name " \" " ))
117
+ (t (concat " \" " " test:test " test-name " \" " )))))
118
+
119
+ (lsp-defun lsp-elixir--run-test ((&Command :arguments? ))
120
+ " Runs tests."
121
+ (let* ((argument (lsp-seq-first arguments?) )
122
+ (file-path (lsp-get argument :filePath ))
123
+ (test-command (lsp-elixir--build-test-command argument)))
124
+ (compile
125
+ (concat " cd " (lsp-workspace-root file-path) " && "
126
+ " mix test --exclude test --include " test-command " " file-path
127
+ " --no-color" ))
128
+ file-path))
129
+
103
130
(lsp-register-custom-settings
104
131
'((" elixirLS.dialyzerEnabled" lsp-elixir-dialyzer-enabled t )
105
132
(" elixirLS.dialyzerWarnOpts" lsp-elixir-dialyzer-warn-opts)
@@ -109,13 +136,15 @@ finding the executable with `exec-path'."
109
136
(" elixirLS.projectDir" lsp-elixir-project-dir)
110
137
(" elixirLS.fetchDeps" lsp-elixir-fetch-deps t )
111
138
(" elixirLS.suggestSpecs" lsp-elixir-suggest-specs t )
112
- (" elixirLS.signatureAfterComplete" lsp-elixir-signature-after-complete t )))
139
+ (" elixirLS.signatureAfterComplete" lsp-elixir-signature-after-complete t )
140
+ (" elixirLS.enableTestLenses" lsp-elixir-enable-test-lenses t )))
113
141
114
142
(lsp-register-client
115
143
(make-lsp-client :new-connection (lsp-stdio-connection (lambda () `(, lsp-clients-elixir-server-executable )))
116
144
:major-modes '(elixir-mode)
117
145
:priority -1
118
146
:server-id 'elixir-ls
147
+ :action-handlers (ht (" elixir.lens.test.run" 'lsp-elixir--run-test ))
119
148
:initialized-fn (lambda (workspace )
120
149
(with-lsp-workspace workspace
121
150
(lsp--set-configuration
0 commit comments