Skip to content

Commit 43474e7

Browse files
committed
fix: respect the vitest.rootConfig if the workspace only has a single folder
1 parent ffe7fd3 commit 43474e7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/api/pkg.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export interface VitestPackage {
3030

3131
function resolveVitestConfig(showWarning: boolean, configOrWorkspaceFile: vscode.Uri): VitestPackage | null {
3232
const folder = vscode.workspace.getWorkspaceFolder(configOrWorkspaceFile)!
33+
if (!folder)
34+
throw new Error(`Workspace folder not found for ${configOrWorkspaceFile}. Does the file exist?`)
35+
3336
const cwd = dirname(configOrWorkspaceFile.fsPath)
3437
const vitest = resolveVitestPackage(dirname(configOrWorkspaceFile.fsPath), folder)
3538

src/config.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ export function getConfigValue<T>(
1515
}
1616

1717
export function getConfig(workspaceFolder?: WorkspaceFolder) {
18-
let workspace: WorkspaceFolder | vscode.Uri | undefined
19-
if (typeof workspaceFolder === 'string')
20-
workspace = vscode.Uri.from({ scheme: 'file', path: workspaceFolder })
21-
else
22-
workspace = workspaceFolder
18+
if (!workspaceFolder && vscode.workspace.workspaceFolders?.length === 1)
19+
workspaceFolder = vscode.workspace.workspaceFolders[0]
2320

24-
const folderConfig = vscode.workspace.getConfiguration('vitest', workspace)
21+
const folderConfig = vscode.workspace.getConfiguration('vitest', workspaceFolder)
2522
const rootConfig = vscode.workspace.getConfiguration('vitest')
2623

2724
const get = <T>(key: string, defaultValue?: T) => getConfigValue<T>(

0 commit comments

Comments
 (0)