(inFolder?: vscode.WorkspaceFolder | string)
| 23 | * @param inFolder - Optionally scopes lookups to the given workspace folder |
| 24 | */ |
| 25 | export 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 | |
| 81 | interface IEditCandidate { |
| 82 | path?: string; |
nothing calls this directly
no test coverage detected