-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
We have a feature to invoke the right cargo test command for the test at caret:
(In VS Code, it is triggered by the Rust Run action)
Currently, it works only for #[test] functions, but it would be useful to run test modules as well.
Here's how the feature works currently:
runnables function discovers #[test] functions:
https://github.com/rust-analyzer/rust-analyzer/blob/0043d7e9c7f27af95cbf299d5b92ce28ba9945ab/crates/ra_editor/src/lib.rs#L119-L140
The function is exposed on Analysis struct (the API between language server and "compiler") here:
https://github.com/rust-analyzer/rust-analyzer/blob/0043d7e9c7f27af95cbf299d5b92ce28ba9945ab/crates/ra_analysis/src/lib.rs#L245-L248
in main_loop/handlers we add information about current Cargo target/package to it and handle, as JSON, to the editor:
To support testing modules, we need to add fully-qualified module name to the command line. The steps to do so would be
- move the
runnablefunction from ra_editor to ra_analysis: ra_editor knows nothing about module - in the
runnablefunction, detect not only functinons, but mods with test functions as well - make a function to compute a
foo::bar::bazpath to a module. See the implementation of crate_root function, which contains "traverse parent modules" logic. - add module path to a
Runnablestruct - adjust the
handle_runnablesfunction to construct a command line, using the full path
