Skip to content

Commit d788a13

Browse files
authored
Add the ability to run elixir tests from test lenses (#2407)
* Add the ability to run elixir tests from test lenses * Run tests with --no-color to work better with the compile buffer * Use lsp-get instead of gethash.
1 parent 4582cac commit d788a13

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Automatically download [[https://github.com/eclipse/lemminx][XML language server Lemminx]]
1212
* Add Vala support.
1313
* Add [[https://github.com/sorbet/sorbet][Sorbet Language Server]] for typechecking Ruby code.
14+
* Add Elixir test lenses support.
1415
** Release 7.0.1
1516
* Introduced ~lsp-diagnostics-mode~.
1617
* Safe renamed ~lsp-flycheck-default-level~ -> ~lsp-diagnostics-flycheck-default-level~

clients/lsp-elixir.el

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ finding the executable with `exec-path'."
100100
:group 'lsp-elixir
101101
:type 'file)
102102

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+
103130
(lsp-register-custom-settings
104131
'(("elixirLS.dialyzerEnabled" lsp-elixir-dialyzer-enabled t)
105132
("elixirLS.dialyzerWarnOpts" lsp-elixir-dialyzer-warn-opts)
@@ -109,13 +136,15 @@ finding the executable with `exec-path'."
109136
("elixirLS.projectDir" lsp-elixir-project-dir)
110137
("elixirLS.fetchDeps" lsp-elixir-fetch-deps t)
111138
("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)))
113141

114142
(lsp-register-client
115143
(make-lsp-client :new-connection (lsp-stdio-connection (lambda () `(,lsp-clients-elixir-server-executable)))
116144
:major-modes '(elixir-mode)
117145
:priority -1
118146
:server-id 'elixir-ls
147+
:action-handlers (ht ("elixir.lens.test.run" 'lsp-elixir--run-test))
119148
:initialized-fn (lambda (workspace)
120149
(with-lsp-workspace workspace
121150
(lsp--set-configuration

0 commit comments

Comments
 (0)