Skip to content

Commit 966358c

Browse files
committed
feat: add ignoreWorkspace and configSearchPatternInclude options
1 parent 97b19fd commit 966358c

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ These options are resolved relative to the [workspace file](https://code.visuals
7272

7373
- `vitest.rootConfig`: The path to your root config file. If you have several Vitest configs, consider using a [Vitest workspace](https://vitest.dev/guide/workspace).
7474
- `vitest.workspaceConfig`: The path to the [Vitest workspace](https://vitest.dev/guide/workspace) config file. You can only have a single workspace config per VSCode workspace.
75+
- `vitest.ignoreWorkspace`: Ignores the workspace resolution step. The extension will only look for `vitest.config` files.
76+
- `vitest.configSearchPatternInclude`: [Glob pattern](https://code.visualstudio.com/docs/editor/glob-patterns) that should be used when this extension looks for config files. Note that this is applied to _config_ files, not test files inside configs. Default: `**/*{vite,vitest}*.config*.{ts,js,mjs,cjs,cts,mts}`.
7577
- `vitest.configSearchPatternExclude`: [Glob pattern](https://code.visualstudio.com/docs/editor/glob-patterns) that should be ignored when this extension looks for config files. Note that this is applied to _config_ files, not test files inside configs. Default: `{**/node_modules/**,**/.*/**,*.d.ts}`. If the extension cannot find Vitest, please open an issue.
7678
- `vitest.shellType`: The method the extension uses to spawn a long-running Vitest process. This is particularly useful if you are using a custom shell script to set up the environment. When using the `terminal` shell type, the websocket connection will be established. Can either be `terminal` or `child_process`. Default: `terminal`.
7779
- `vitest.nodeExecutable`: The path to the Node.js executable. If not assigned, tries to find Node.js path via a PATH variable or a `which` command. This is applied only when `vitest.shellType` is `child_process`.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@
142142
"type": "string",
143143
"scope": "window"
144144
},
145+
"vitest.ignoreWorkspace": {
146+
"description": "Ignore workspace files resolution.",
147+
"type": "boolean",
148+
"default": false,
149+
"scope": "window"
150+
},
151+
"vitest.configSearchPatternInclude": {
152+
"markdownDescription": "A VSCode [glob pattern](https://code.visualstudio.com/docs/editor/glob-patterns) to include files from the search for Vitest config files. This pattern affects only regular config files.",
153+
"type": "string",
154+
"default": "**/*{vite,vitest}*.config*.{ts,js,mjs,cjs,cts,mts}",
155+
"scope": "window"
156+
},
145157
"vitest.configSearchPatternExclude": {
146158
"markdownDescription": "A VSCode [glob pattern](https://code.visualstudio.com/docs/editor/glob-patterns) to exclude files from the search for Vitest config files. This pattern affects both workspace and regular config files.",
147159
"type": "string",

src/api/pkg.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ async function resolveVitestWorkspaceConfigs(showWarning: boolean) {
235235
const userWorkspace = config.workspaceConfig
236236
const rootConfig = config.rootConfig
237237

238+
if (config.ignoreWorkspace) {
239+
return { meta: [], warned: false }
240+
}
241+
238242
if (userWorkspace)
239243
log.info('[API] Using user workspace config:', userWorkspace)
240244

@@ -280,7 +284,10 @@ async function resolveVitestConfigs(showWarning: boolean) {
280284

281285
const configs = rootConfig
282286
? [vscode.Uri.file(rootConfig)]
283-
: await vscode.workspace.findFiles(configGlob, config.configSearchPatternExclude)
287+
: await vscode.workspace.findFiles(
288+
config.configSearchPatternInclude || configGlob,
289+
config.configSearchPatternExclude,
290+
)
284291

285292
const configsByFolder = configs.reduce<Record<string, vscode.Uri[]>>((acc, config) => {
286293
const dir = dirname(config.fsPath)

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { WorkspaceConfiguration, WorkspaceFolder } from 'vscode'
22
import { homedir } from 'node:os'
33
import { dirname, isAbsolute, resolve } from 'node:path'
44
import * as vscode from 'vscode'
5+
import { configGlob } from './constants'
56

67
export const extensionId = 'vitest.explorer'
78
export const testControllerId = 'vitest'
@@ -41,6 +42,11 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {
4142
'{**/node_modules/**,**/.*/**,**/*.d.ts}',
4243
)!
4344

45+
const configSearchPatternInclude = get<string>(
46+
'configSearchPatternInclude',
47+
configGlob,
48+
) || configGlob
49+
4450
const vitestPackagePath = get<string | undefined>('vitestPackagePath')
4551
const resolvedVitestPackagePath = workspaceFolder && vitestPackagePath
4652
? resolve(
@@ -65,6 +71,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {
6571

6672
const debugOutFiles = get<string[]>('debugOutFiles', [])
6773
const applyDiagnostic = get<boolean>('applyDiagnostic', true)
74+
const ignoreWorkspace = get<boolean>('ignoreWorkspace', false) ?? false
6875

6976
return {
7077
env: get<null | Record<string, string>>('nodeEnv', null),
@@ -81,7 +88,9 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {
8188
vitestPackagePath: resolvedVitestPackagePath,
8289
workspaceConfig: resolveConfigPath(workspaceConfig),
8390
rootConfig: resolveConfigPath(rootConfigFile),
91+
configSearchPatternInclude,
8492
configSearchPatternExclude,
93+
ignoreWorkspace,
8594
maximumConfigs: get<number>('maximumConfigs', 5),
8695
nodeExecutable: resolveConfigPath(nodeExecutable),
8796
disableWorkspaceWarning: get<boolean>('disableWorkspaceWarning', false),

0 commit comments

Comments
 (0)