@@ -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