From 6336e3bbd6ddbac386240dc8ee2b02a7e2b702da Mon Sep 17 00:00:00 2001 From: Wilhelm Hugo Kirschbaum Date: Wed, 9 Dec 2020 22:53:13 +0200 Subject: [PATCH 1/3] Add the ability to run elixir tests from test lenses --- CHANGELOG.org | 1 + clients/lsp-elixir.el | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index b94c842e71..415c0dda78 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -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~ diff --git a/clients/lsp-elixir.el b/clients/lsp-elixir.el index 1fce2f6f01..642e5004be 100644 --- a/clients/lsp-elixir.el +++ b/clients/lsp-elixir.el @@ -100,6 +100,38 @@ 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 (gethash "testName" argument)) + (module (gethash "module" argument)) + (describe (gethash "describe" argument))) + (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 (gethash "filePath" argument)) + (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)) + file-path)) + (lsp-register-custom-settings '(("elixirLS.dialyzerEnabled" lsp-elixir-dialyzer-enabled t) ("elixirLS.dialyzerWarnOpts" lsp-elixir-dialyzer-warn-opts) @@ -109,13 +141,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 From 0cedb0fdefdae44f3df261b7c879d1916223108b Mon Sep 17 00:00:00 2001 From: Wilhelm Hugo Kirschbaum Date: Mon, 14 Dec 2020 22:42:09 +0200 Subject: [PATCH 2/3] Run tests with --no-color to work better with the compile buffer --- clients/lsp-elixir.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clients/lsp-elixir.el b/clients/lsp-elixir.el index 642e5004be..297bcf89e9 100644 --- a/clients/lsp-elixir.el +++ b/clients/lsp-elixir.el @@ -129,7 +129,8 @@ finding the executable with `exec-path'." "mix test --exclude test --include " test-command " " - file-path)) + file-path + " --no-color")) file-path)) (lsp-register-custom-settings From 30c035d5ace77023b7f0af3dc3fcb05cb647616a Mon Sep 17 00:00:00 2001 From: Wilhelm Hugo Kirschbaum Date: Mon, 14 Dec 2020 23:33:01 +0200 Subject: [PATCH 3/3] Use lsp-get instead of gethash. --- clients/lsp-elixir.el | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/clients/lsp-elixir.el b/clients/lsp-elixir.el index 297bcf89e9..37994fe38a 100644 --- a/clients/lsp-elixir.el +++ b/clients/lsp-elixir.el @@ -108,9 +108,9 @@ finding the executable with `exec-path'." (defun lsp-elixir--build-test-command (argument) "Builds the test command from the ARGUMENT." - (let ((test-name (gethash "testName" argument)) - (module (gethash "module" argument)) - (describe (gethash "describe" 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 "\"" )) @@ -119,18 +119,12 @@ finding the executable with `exec-path'." (lsp-defun lsp-elixir--run-test ((&Command :arguments?)) "Runs tests." (let* ((argument (lsp-seq-first arguments?)) - (file-path (gethash "filePath" argument)) + (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")) + (concat "cd " (lsp-workspace-root file-path) " && " + "mix test --exclude test --include " test-command " " file-path + " --no-color")) file-path)) (lsp-register-custom-settings