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

Function promptToOpen

src/ui/debugNpmScript.ts:191–216  ·  view source on GitHub ↗
(
  method: 'showWarningMessage' | 'showErrorMessage',
  message: string,
  file: string,
)

Source from the content-addressed store, hash-verified

189const defaultPackageJsonContents = `{\n "scripts": {\n \n }\n}\n`;
190
191async function promptToOpen(
192 method: 'showWarningMessage' | 'showErrorMessage',
193 message: string,
194 file: string,
195) {
196 const openAction = l10n.t('Edit package.json');
197 if ((await vscode.window[method](message, openAction)) !== openAction) {
198 return;
199 }
200
201 // If the file exists, open it, otherwise create a new untitled file and
202 // fill it in with some minimal "scripts" section.
203 if (fs.existsSync(file)) {
204 const document = await vscode.workspace.openTextDocument(file);
205 await vscode.window.showTextDocument(document);
206 return;
207 }
208
209 const document = await vscode.workspace.openTextDocument(
210 vscode.Uri.file(file).with({ scheme: 'untitled' }),
211 );
212 const editor = await vscode.window.showTextDocument(document);
213 await editor.edit(e => e.insert(new vscode.Position(0, 0), defaultPackageJsonContents));
214 const pos = new vscode.Position(2, 5);
215 editor.selection = new vscode.Selection(pos, pos);
216}

Callers 1

findScriptsFunction · 0.85

Calls 3

withMethod · 0.80
editMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected