rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 176 forks source link

Run test on point #543

Closed victoronascimento closed 2 months ago

victoronascimento commented 2 months ago

IMHO this function should be ported from rustic or with a new implementation. It is a time saver and huge contributor of a fast feedback cycle.

Rustic provides:

;;;###autoload
(defun rustic-cargo-current-test ()
  "Run 'cargo test' for the test near point."
  (interactive)
  (rustic-compilation-process-live)
  (-if-let (test-to-run (setq rustic-test-arguments
                              (rustic-cargo--get-test-target)))
      (rustic-cargo-run-test test-to-run)
    (message "Could not find test at point.")))

Not sure how it would migrate to rust-mode, but I really think this would greatly enhance the devX.

Thanks a lot for your work and if this is acceptable I can try a PR.

psibi commented 2 months ago

I would lean towards keeping rust-mode light-weight and small. You can still use rustic which is built on top of rust-mode.

BTW, You could also use this similar feature currently by using lsp-mode and rust-mode. You can use inlay hints to select the current test on the buffer and run them accordingly. I use that often in rustic-mode.

victoronascimento commented 2 months ago

Hi @psibi ! Thanks for the reply!

While I totally agree with keeping the mode as lean as possible, I think that having a command like cargo-test and not having cargo-test-on-point (or any name we come up with) is strange. To me, the later would be used much more often than the prior. If we were to "choose" here, I would rather have the later than the first one IMHO.

In my specific case (which is not to say I should be used as reliable data), I'd love to avoid another big package which has many things duplicated as this one. Also, a whole package (and a big one that has not been updated recently) just for this function is kinda not optimal.

Also, I am using eglot and not lsp-mode (not a 100% rational decision, but trying to keep less dependencies) and I would love to see if the same setup as the one you suggested could be applied.

In any case, I totally understand if you don't want this to be in the core rust-mode. In Elixir land, there is a famous package just to handle tests (exunit.el) and the core package (which I somewhat co-maintain) only has a mix command (which is similar to cargo in this case). Maybe we could have a rust specific test package.

Thanks once again for all your work! It is much appreciated.

psibi commented 2 months ago

(and a big one that has not been updated recently) just for this function is kinda not optimal.

I have been maintaining a fork that is updated: https://github.com/psibi/rustic For background on why a fork, this issue has some details on it: https://github.com/psibi/rustic/issues/15

Also, I am using eglot and not lsp-mode (not a 100% rational decision, but trying to keep less dependencies) and I would love to see if the same setup as the one you suggested could be applied.

Looks like elgot does support inlay hints: https://www.gnu.org/software/emacs/manual/html_node/eglot/Eglot-Commands.html So I believe it should be possible (although I'm not 100% certain as I use lsp-mode personally). Infact, looking at the docs of lsp-mode - it seems to be supporting the exact use case that you are asking: https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#find-and-execute-tests-related-to-current-position (This is different than running the test via inlay hints).

victoronascimento commented 2 months ago

Thanks once again @psibi ! It would be great to have this fork on Melpa under a different name.

If you could, please, show the inlay trick with lsp-mode here? I will try to adapt with eglot and then close this issue.

Thanks a lot once again!

victoronascimento commented 2 months ago

I've seen the code from cargo.el and adapted to my use case!

I'll be closing this one! Thanks once again @psibi !