Test/Spec Switcher
I work in a codebase that doesn't have a standard way of naming or locating test files. So I wrote this extension which uses fuzzy search and some other clever stuff to try and locate the matching test/source file and quickly switch to it (and vice versa). Ideally we would just have a standard way to organise and name our files, but this was more fun to make.
Features
Use Ctrl+Alt+.
(mac: Ctrl+Cmd+.
) to switch between source/test code files and their matching test/source files. The extension will do its best to find the matching test/source file in the workspace. It will also remember which file you came from, so using the extension again will take you back.
If you want to manually select the file to switch to (sometimes the extension will get it wrong) use Ctrl+Shift+Alt+.
(mac: Ctrl+Shift+Cmd+.
).
The commands are also available in the command pallette under SpecSwitcher: Switch to test/code
and SpecSwitcher: Manually switch to test/code
.
Extension Settings
This extension contributes the following settings:
spec-switcher.useGitIgnoreFile
: enable to exclude gitignored files from matches (enabled by default).
spec-switcher.useCustomFilePicker
: enable to use a custom file picker for the "Let me choose" override. The custom picker is slower than the default vscode quick open, but handles cancellations better (disabled by default).
Disabling for a specific language
Maybe there is an extension that provides a better form of this functionality for a given language and you want to reuse the shortcut. To disable the extension for a given language add the following to your keybindings.json (command pallette: Preferences: Open Keyboard Shortcuts (JSON)
):
{
"key": "ctrl+cmd+.",
"command": "spec-switcher.switch",
"when": "editorLangId != ruby"
}
{
"key": "ctrl+cmd+.",
"command": "-spec-switcher.switch"
}