diff --git a/README.md b/README.md index 7ab91493..0f2fe217 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,16 @@ These options are resolved relative to the [workspace file](https://code.visuals - `vitest.maximumConfigs`: The maximum amount of configs that Vitest extension can load. If exceeded, the extension will show a warning suggesting to use a workspace config file. Default: `3` - `vitest.logLevel`: How verbose should the logger be in the "Output" channel. Default: `info` +### Commands + +You can reveal the current test file in the test explorer view by selecting the "Reveal in Test Explorer" option (the last option on the screenshot) in the file context: + +![Reveal test in explorer](./img/reveal-in-explorer.png "Reveal test in explorer") + +You can also type the same command in the quick picker while the file is open. + +![Reveal test in explorer](./img/reveal-in-picker.png "Reveal test in explorer") + ### Experimental If the extension hangs, consider enabling `vitest.experimentalStaticAstCollect` option to use static analysis instead of actually running the test file every time you make a change which can cause visible hangs if it takes a long time to setup the test. diff --git a/img/reveal-in-explorer.png b/img/reveal-in-explorer.png new file mode 100644 index 00000000..baf083e1 Binary files /dev/null and b/img/reveal-in-explorer.png differ diff --git a/img/reveal-in-picker.png b/img/reveal-in-picker.png new file mode 100644 index 00000000..60c406ba Binary files /dev/null and b/img/reveal-in-picker.png differ diff --git a/package.json b/package.json index aa94e146..d8c46754 100644 --- a/package.json +++ b/package.json @@ -75,9 +75,20 @@ "title": "Show Shell Terminal", "command": "vitest.showShellTerminal", "category": "Vitest" + }, + { + "title": "Reveal in Test Explorer", + "command": "vitest.revealInTestExplorer", + "category": "Vitest" } ], "menus": { + "editor/title/context": [ + { + "command": "vitest.revealInTestExplorer", + "when": "vitest.testFiles && resourcePath in vitest.testFiles" + } + ], "commandPalette": [ { "command": "vitest.updateSnapshot", diff --git a/src/extension.ts b/src/extension.ts index a6f92af7..555beb49 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -155,9 +155,10 @@ class VitestExtension { }) for (const api of this.api.folderAPIs) { + const files = await api.getFiles() await this.testTree.watchTestFilesInWorkspace( api, - await api.getFiles(), + files, ) } } @@ -297,6 +298,18 @@ class VitestExtension { vscode.commands.registerCommand('vitest.openOutput', () => { log.openOuput() }), + vscode.commands.registerCommand('vitest.revealInTestExplorer', async (uri: vscode.Uri | undefined) => { + if (uri === undefined) { + uri = vscode.window.activeTextEditor?.document.uri + } + if (!(uri instanceof vscode.Uri)) { + return + } + const testItems = this.testTree.getFileTestItems(uri.fsPath) + if (testItems[0]) { + vscode.commands.executeCommand('vscode.revealTestInExplorer', testItems[0]) + } + }), vscode.commands.registerCommand('vitest.showShellTerminal', async () => { const apis = this.api?.folderAPIs .filter(api => api.process instanceof VitestTerminalProcess) diff --git a/src/testTree.ts b/src/testTree.ts index 30a4d557..97a88163 100644 --- a/src/testTree.ts +++ b/src/testTree.ts @@ -159,6 +159,11 @@ export class TestTree extends vscode.Disposable { const cachedItems = this.testItemsByFile.get(normalizedFile) || [] cachedItems.push(testFileItem) this.testItemsByFile.set(normalizedFile, cachedItems) + vscode.commands.executeCommand( + 'setContext', + 'vitest.testFiles', + Array.from(this.testItemsByFile.keys()), + ) return testFileItem }