You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: switch between a Ruby file and its test (spec) file #33
Basically, the subject. It's a pretty common piece of functionality for a Ruby extension IMHO.
Also, there can be a config to map custom relations between files and their specs (e.g. from app/controllers/{file}.rb to spec/requests/api/v1/{file}_spec.rb.
#!/bin/sh# Check if a filename is providedif [ "$#"-ne 1 ];thenecho"Usage: $0 <filename>"exit 1
fi# Get the provided filename
filename=$1# Determine the alternative fileif [[ "$filename"=~ _spec\.rb$ ]];then# If the file is a spec file, convert it to the corresponding regular Ruby file
alternative_file=$(echo "$filename"| sed 's|^spec/|app/|; s|_spec\.rb$|.rb|')else# If the file is a regular Ruby file, convert it to the corresponding spec file
alternative_file=$(echo "$filename"| sed 's|^app/|spec/|; s|\.rb$|_spec.rb|')fiecho"$alternative_file"
Reacted by Vitaly Slobodin, Cédric Delalande, Kasper Timm Hansen and Dat Le-Tien
This feature was added to Ruby LSP in Shopify/ruby-lsp#2985 and uses a custom LSP request along with integration with VS Code.
The PR description also shows how it can be used with NeoVim, and I imagine something similar would be possible for Zed once scripting is supported (there's a long discussion here).
@asok's approach of shelling out to zed is interesting, but I can't think how that would be hooked into the language server.
I got this working using a task that I assigned to a keyboard shortcut. You just need an executable that can take a file as input and then launch zed to another file by shelling out. If it’s possible to include a task and have it point to an executable in the extension, it could be doable.
I made a rails helper in a similar vain to the zed-test-toggle. It allows jumping between a controller method and the related view if it exists and also a view and the respective controller + action. It takes into account inheritance and what not. It was a major bottleneck for me switching off of vs code forks so hopefully this helps others too until scripting is supported
Activity
vitallium commentedon Feb 18, 2025
Hi, this would be amazing, but unfortunately, the Zed Extension API is limited, and there is no way to implement this currently.
asok commentedon Feb 28, 2025
For anyone looking for some kind of a solution for this I'm able to employ tasks to achieve this.
Basically I have this in my
tasks.json:and such script in my PATH:
andyw8 commentedon Mar 24, 2025
This feature was added to Ruby LSP in Shopify/ruby-lsp#2985 and uses a custom LSP request along with integration with VS Code.
The PR description also shows how it can be used with NeoVim, and I imagine something similar would be possible for Zed once scripting is supported (there's a long discussion here).
@asok's approach of shelling out to
zedis interesting, but I can't think how that would be hooked into the language server.cc @jenny-codes
joeldrapper commentedon Apr 16, 2025
I got this working using a task that I assigned to a keyboard shortcut. You just need an executable that can take a file as input and then launch zed to another file by shelling out. If it’s possible to include a task and have it point to an executable in the extension, it could be doable.
andyw8 commentedon Apr 16, 2025
I suspect it wouldn't be viable since the extension compiles down to WebAssembly, but you could perhaps have the extension auto-install a tiny gem?
MoskitoHero commentedon Apr 17, 2025
I just started writing that gem yesterday. It works locally, I just need a little time to package it.
MoskitoHero commentedon Apr 17, 2025
Here you go, it’s quite rough for now, but it does the job (on my projects). Feel free to make PRs to match more settings / frameworks.
https://github.com/MoskitoHero/zed-test-toggle
andyw8 commentedon Apr 17, 2025
Nice! Had to make a small fix to the README example:
MoskitoHero/zed-test-toggle#1
Tonksthebear commentedon Jun 30, 2025
I made a rails helper in a similar vain to the zed-test-toggle. It allows jumping between a controller method and the related view if it exists and also a view and the respective controller + action. It takes into account inheritance and what not. It was a major bottleneck for me switching off of vs code forks so hopefully this helps others too until scripting is supported
https://github.com/Tonksthebear/zed-rails-jumper