Skip to content

Commit

Permalink
feat: add "reveal" option
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 20, 2024
1 parent c40fce6 commit efd5488
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added img/reveal-in-explorer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/reveal-in-picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/testTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit efd5488

Please sign in to comment.