diff --git a/package.json b/package.json index 42003eec..4dedfb13 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,7 @@ "@rauschma/stringio": "^1.4.0", "@vue/reactivity": "^3.2.33", "fs-extra": "^10.0.1", + "fuse.js": "^6.6.2", "mighty-promise": "^0.0.8", "minimatch": "^3.1.1", "semver": "^7.3.5", diff --git a/src/extension.ts b/src/extension.ts index f80bfa7b..cd74839e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -17,9 +17,8 @@ export async function activate(context: vscode.ExtensionContext) { return; } - const config = getConfig(); if ( - !config.enable && + !getConfig().enable && !(await isVitestEnv(vscode.workspace.workspaceFolders[0].uri.fsPath)) ) { return; @@ -86,6 +85,7 @@ export async function activate(context: vscode.ExtensionContext) { vscode.window.visibleTextEditors.forEach((x) => fileDiscoverer.discoverTestFromDoc(ctrl, x.document) ); + context.subscriptions.push( ctrl, // TODO diff --git a/src/watch.ts b/src/watch.ts index 671fe8f9..20119a22 100644 --- a/src/watch.ts +++ b/src/watch.ts @@ -7,6 +7,7 @@ import { TestRunRequest, workspace, } from "vscode"; +import Fuse from "fuse.js"; import { buildWatchClient } from "./pure/watch/client"; import type { File, Task } from "vitest"; import { TestFileDiscoverer } from "./discover"; @@ -283,8 +284,10 @@ export class TestWatcher extends Disposable { if (ans) { candidates.delete(ans); } else { - // TODO: blur match; - throw new Error("not implemented"); + ans = new Fuse(Array.from(candidates), { keys: ["pattern"] }).search( + task.name, + )[0]?.item; + // should not delete ans from candidates here, because there are usages like `test.each` } return ans; diff --git a/yarn.lock b/yarn.lock index b5f2499b..84b18192 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1232,6 +1232,11 @@ functional-red-black-tree@^1.0.1: resolved "https://registry.npmmirror.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz" integrity sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g== +fuse.js@^6.6.2: + version "6.6.2" + resolved "https://registry.npmmirror.com/fuse.js/-/fuse.js-6.6.2.tgz#fe463fed4b98c0226ac3da2856a415576dc9a111" + integrity sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA== + get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz"