Skip to content

Commit

Permalink
feat: add toggle watch mode to command palette
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed May 16, 2022
1 parent 3c3a386 commit 7b17988
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,31 @@
"title": "Start Watch Mode",
"command": "vitest.startWatching",
"category": "Vitest"
},
{
"title": "Stop Watch Mode",
"command": "vitest.stopWatching",
"category": "Vitest"
},
{
"title": "Toggle Watch Mode",
"command": "vitest.toggleWatching",
"category": "Vitest"
}
],
"menus": {
"commandPalette": [
{
"command": "vitest.updateSnapshot",
"when": "false"
},
{
"command": "vitest.startWatching",
"when": "false"
},
{
"command": "vitest.stopWatching",
"when": "false"
}
],
"testing/item/context": [
Expand Down Expand Up @@ -107,7 +125,7 @@
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsup ./src/extension.ts --external vscode",
"compile": "tsup ./src/extension.ts --external vscode --minify",
"watch": "tsup ./src/extension.ts --external vscode --watch --sourcemap",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
Expand Down
1 change: 1 addition & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum Command {
StartWatching = "vitest.startWatching",
StopWatching = "vitest.stopWatching",
UpdateSnapshot = "vitest.updateSnapshot",
ToggleWatching = "vitest.toggleWatching",
}
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ function registerWatchHandler(
testWatcher!.dispose();
},
),
vscode.commands.registerCommand(
Command.ToggleWatching,
() => {
if (testWatcher.isWatching.value) {
testWatcher.dispose();
} else {
testWatcher.watch();
}
},
),
);

ctrl.createRunProfile(
Expand Down

0 comments on commit 7b17988

Please sign in to comment.