Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Automatically download [[https://github.com/eclipse/lemminx][XML language server Lemminx]]
* Add Vala support.
* Add [[https://github.com/sorbet/sorbet][Sorbet Language Server]] for typechecking Ruby code.
* Add Elixir test lenses support.
** Release 7.0.1
* Introduced ~lsp-diagnostics-mode~.
* Safe renamed ~lsp-flycheck-default-level~ -> ~lsp-diagnostics-flycheck-default-level~
Expand Down
31 changes: 30 additions & 1 deletion clients/lsp-elixir.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ 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)
Expand All @@ -109,13 +136,15 @@ finding the executable with `exec-path'."
("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.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
Expand Down