I’d like to make a build task that runs the unit test I’m currently working on in my editor. Today, that involves Rust. Tomorrow, that might involve Python. Either way, I wish I could pass in the function name so that I could run an action like:
cargo test $test_function_name
pytest -k $test_function_name
which would make it much easier to quickly iterate on a single test. I can kinda hack around this by writing a script to map the filename + current line number to the function name, but that’s brittle and janky. It’d be much cleaner if Nova could pass that in for me.
Oh hey I have an unpublished Rust extension that allows for this kind of task customization!
At least I think so… by passing the current function name to cargo test do you mean that invoking the task should dynamically determine what test function to run based on your current cursor position?
If so, I guess the Cargo task in the extension doesn’t go that far, but still makes this use case easier for me. It is is an excellent idea though and, IIRC, rust-analyzer might have a custom LSP method that could be used to implement this in a more cohesive manner.
As far as generalizing this as a core Nova feature, I suppose they could expose the function name that the cursor is located within (if any) as a variable token to be used in DIY task scripts… but my hunch would be that it’d still probably fall on the language syntax to reliably allow for that.
By the way, If you or anyone else would be interested, I’d be happy to put out a pre release build of the extension on GitHub for anyone to manually install and play around with. I’ve only been building it out sporadically as time permits, which is why it’s unpublished. But I’ve been thinking about making it public anyways as it’s pretty much feature complete at this point.
I was inspired to think about this when I saw the name of the current function in the… what is it, the navigation bar? at the top of the file. I was looking at a Rust file at the time and I’m sure the information came from the LSP. Maybe Nova implements that natively, but I’d be surprised.