diff --git a/README.md b/README.md index e9773f45..50dbf1ef 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ These options are resolved relative to the [workspace file](https://code.visuals - `vitest.debugExclude`: Excludes files matching specified glob patterns from debugging. Default: `[\"/**\", \"**/node_modules/**\"]` - `vitest.debugOutFiles`: If source maps are enabled, these glob patterns specify the generated JavaScript files. If a pattern starts with `!` the files are excluded. If not specified, the generated code is expected in the same directory as its source. Default: `["${workspaceFolder}/**/*.(m|c|)js", "!**/node_modules/**"]` -- `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.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: `5` - `vitest.logLevel`: How verbose should the logger be in the "Output" channel. Default: `info` - `vitest.applyDiagnostic`: Show a squiggly line where the error was thrown. This also enables the error count in the File Tab. Default: `true` - `vitest.experimentalStaticAstCollect`: uses AST parses to collect tests instead of running files and collecting them at runtime. Default: `true` diff --git a/package.json b/package.json index c15cd2a5..8eca8dde 100644 --- a/package.json +++ b/package.json @@ -167,7 +167,7 @@ "vitest.maximumConfigs": { "description": "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.", "type": "number", - "default": 3, + "default": 5, "scope": "window" }, "vitest.debugExclude": { diff --git a/src/api.ts b/src/api.ts index 17660093..4c272924 100644 --- a/src/api.ts +++ b/src/api.ts @@ -4,7 +4,7 @@ import * as vscode from 'vscode' import { log } from './log' import type { ExtensionWorkerEvents, SerializedTestSpecification, VitestRPC } from './api/rpc' import type { VitestPackage } from './api/pkg' -import { createVitestWorkspaceFile, noop, showVitestError } from './utils' +import { showVitestError } from './utils' import { createVitestTerminalProcess } from './api/terminal' import { getConfig } from './config' import { createVitestProcess } from './api/child_process' @@ -280,7 +280,7 @@ export async function resolveVitestAPI(workspaceConfigs: VitestPackage[], config return depthA - depthB }) - const maximumConfigs = getConfig().maximumConfigs ?? 3 + const maximumConfigs = getConfig().maximumConfigs ?? 5 const workspaceRoots: string[] = apis .map(api => api.workspaceSource ? dirname(api.workspaceSource) : null) @@ -345,27 +345,31 @@ function isCoveredByWorkspace(workspacesRoots: string[], currentConfig: string): } function warnPerformanceConfigLimit(configsToResolve: VitestPackage[]) { - const maximumConfigs = getConfig().maximumConfigs ?? 3 + const maximumConfigs = getConfig().maximumConfigs ?? 5 const warningMessage = [ - 'Vitest found multiple config files.', + 'Vitest found multiple projects.', `The extension will use only the first ${maximumConfigs} due to performance concerns.`, - 'Consider using a workspace configuration to group your configs or increase', + 'Consider using a projects configuration to group your configs or increase', 'the limit via "vitest.maximumConfigs" option.', ].join(' ') const folders = Array.from(new Set(configsToResolve.map(c => c.folder))) - const allConfigs = [...configsToResolve] - // remove all but the first 3 + // remove all but the first 5 const discardedConfigs = configsToResolve.splice(maximumConfigs) if (folders.every(f => getConfig(f).disableWorkspaceWarning !== true)) { vscode.window.showWarningMessage( warningMessage, - 'Create vitest.workspace.js', + 'Documentation', 'Disable notification', ).then((result) => { - if (result === 'Create vitest.workspace.js') - createVitestWorkspaceFile(allConfigs).catch(noop) + if (result === 'Documentation') { + vscode.commands.executeCommand( + 'vscode.open', + // /workspace redirects to /projects on the new version + vscode.Uri.parse('https://vitest.dev/guide/workspace'), + ) + } if (result === 'Disable notification') { folders.forEach((folder) => { diff --git a/src/config.ts b/src/config.ts index c4d2c469..b278d1cc 100644 --- a/src/config.ts +++ b/src/config.ts @@ -82,7 +82,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) { workspaceConfig: resolveConfigPath(workspaceConfig), rootConfig: resolveConfigPath(rootConfigFile), configSearchPatternExclude, - maximumConfigs: get('maximumConfigs', 3), + maximumConfigs: get('maximumConfigs', 5), nodeExecutable: resolveConfigPath(nodeExecutable), disableWorkspaceWarning: get('disableWorkspaceWarning', false), debuggerPort: get('debuggerPort') || undefined, diff --git a/src/utils.ts b/src/utils.ts index 2548c590..199e1610 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,33 +13,6 @@ export function formatPkg(pkg: VitestPackage) { return `Vitest v${pkg.version} (${relative(dirname(pkg.cwd), pkg.id)})` } -export async function createVitestWorkspaceFile(vitest: VitestPackage[]) { - const folders = new Set(vitest.map(x => x.folder)) - const encoder = new TextEncoder() - const promises = [...folders].map(async (folder) => { - const configFiles = vitest.filter(x => x.folder === folder).map(x => relative(folder.uri.fsPath, x.configFile!)) - const ext = configFiles.every(x => /\.m?ts$/.test(x)) ? 'ts' : 'js' - const workspaceFileUri = vscode.Uri.joinPath(folder.uri, `vitest.workspace.${ext}`) - - const workspaceContent = ` -import { defineWorkspace } from 'vitest/config' - -export default defineWorkspace([ - ${configFiles.map(file => `"./${file}"`).join(',\n ')} -]) -`.trimStart() - - await vscode.workspace.fs.writeFile(workspaceFileUri, encoder.encode(workspaceContent)) - return await vscode.workspace.openTextDocument(workspaceFileUri) - }) - - const results = await Promise.all(promises) - if (results[0]) - await vscode.window.showTextDocument(results[0]) - - await vscode.window.showInformationMessage('Created vitest.workspace.js. You might need to run \`npm i --save-dev vitest\` in the root folder to install Vitest.') -} - function _showVitestError(message: string, error?: any) { if (error) log.error(error)