|
1 | 1 | import { sep } from 'node:path' |
2 | 2 | import * as vscode from 'vscode' |
3 | 3 | import { basename, dirname } from 'pathe' |
4 | | -import { testControllerId } from './config' |
| 4 | +import { getConfig, testControllerId } from './config' |
5 | 5 | import type { VitestAPI } from './api' |
6 | 6 | import { resolveVitestAPI, resolveVitestPackages } from './api' |
7 | 7 | import { TestRunner } from './runner/runner' |
8 | 8 | import { TestTree } from './testTree' |
9 | 9 | import { configGlob, workspaceGlob } from './constants' |
10 | 10 | import { log } from './log' |
| 11 | +import { createVitestWorkspaceFile, noop } from './utils' |
11 | 12 |
|
12 | 13 | export async function activate(context: vscode.ExtensionContext) { |
13 | 14 | const extension = new VitestExtension() |
@@ -52,6 +53,26 @@ class VitestExtension { |
52 | 53 | return |
53 | 54 | } |
54 | 55 |
|
| 56 | + const configFiles = vitest.filter(x => x.configFile) |
| 57 | + |
| 58 | + if (configFiles.length > 3 && getConfig().disableWorkspaceNotification !== true) { |
| 59 | + vscode.window.showWarningMessage( |
| 60 | + `Vitest found ${configFiles.length} config files. For better performance, consider using a workspace configuration.`, |
| 61 | + 'Create vitest.workspace.js', |
| 62 | + 'Disable notification', |
| 63 | + ).then((result) => { |
| 64 | + if (!result) |
| 65 | + return |
| 66 | + if (result === 'Create vitest.workspace.js') |
| 67 | + createVitestWorkspaceFile(configFiles).catch(noop) |
| 68 | + |
| 69 | + if (result === 'Disable notification') { |
| 70 | + const rootConfig = vscode.workspace.getConfiguration('vitest') |
| 71 | + rootConfig.update('disableWorkspaceNotification', true) |
| 72 | + } |
| 73 | + }) |
| 74 | + } |
| 75 | + |
55 | 76 | const folders = new Set(vitest.map(x => x.folder)) |
56 | 77 | this.testTree.reset(Array.from(folders)) |
57 | 78 |
|
@@ -128,7 +149,7 @@ class VitestExtension { |
128 | 149 | this.disposables = [ |
129 | 150 | vscode.workspace.onDidChangeWorkspaceFolders(() => this.defineTestProfiles(false)), |
130 | 151 | vscode.workspace.onDidChangeConfiguration((event) => { |
131 | | - if (event.affectsConfiguration('vitest')) |
| 152 | + if (event.affectsConfiguration('vitest.packagePath') || event.affectsConfiguration('vitest.nodeExecutable')) |
132 | 153 | this.defineTestProfiles(false) |
133 | 154 | }), |
134 | 155 | ] |
|
0 commit comments