MCPcopy Index your code
hub / github.com/microsoft/vscode-js-debug / debugNpmScript

Function debugNpmScript

src/ui/debugNpmScript.ts:25–79  ·  view source on GitHub ↗
(inFolder?: vscode.WorkspaceFolder | string)

Source from the content-addressed store, hash-verified

23 * @param inFolder - Optionally scopes lookups to the given workspace folder
24 */
25export async function debugNpmScript(inFolder?: vscode.WorkspaceFolder | string) {
26 const scripts = await findScripts(inFolder ? [inFolder] : undefined);
27 if (!scripts) {
28 return; // cancelled
29 }
30
31 const runScript = async (script: IScript) => {
32 const workspaceFolder = vscode.workspace.getWorkspaceFolder(
33 vscode.Uri.file(script.directory),
34 );
35 runCommand(
36 vscode.commands,
37 Commands.CreateDebuggerTerminal,
38 await getRunScriptCommand(script.name, workspaceFolder),
39 workspaceFolder,
40 { cwd: script.directory },
41 );
42 };
43
44 if (scripts.length === 1) {
45 return runScript(scripts[0]);
46 }
47
48 // For multi-root workspaces, prefix the script name with the workspace
49 // directory name so the user knows where it's coming from.
50 const multiDir = scripts.some(s => s.directory !== scripts[0].directory);
51 const quickPick = vscode.window.createQuickPick<ScriptPickItem>();
52
53 let lastDir: string | undefined;
54 const items: ScriptPickItem[] = [];
55 for (const script of scripts) {
56 if (script.directory !== lastDir && multiDir) {
57 items.push({
58 label: path.basename(script.directory),
59 kind: vscode.QuickPickItemKind.Separator,
60 });
61 lastDir = script.directory;
62 }
63
64 items.push({
65 script,
66 label: script.name,
67 description: script.command,
68 });
69 }
70 quickPick.items = items;
71
72 quickPick.onDidAccept(async () => {
73 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74 runScript(quickPick.selectedItems[0].script!);
75 quickPick.dispose();
76 });
77
78 quickPick.show();
79}
80
81interface IEditCandidate {
82 path?: string;

Callers

nothing calls this directly

Calls 5

findScriptsFunction · 0.85
runScriptFunction · 0.85
pushMethod · 0.65
disposeMethod · 0.65
showMethod · 0.65

Tested by

no test coverage detected