MCPcopy Create free account
hub / github.com/Snapchat/Valdi / promptToOpen

Function promptToOpen

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

Source from the content-addressed store, hash-verified

157const defaultPackageJsonContents = `{\n "scripts": {\n \n }\n}\n`;
158
159async function promptToOpen(
160 method: 'showWarningMessage' | 'showErrorMessage',
161 message: string,
162 file: string,
163) {
164 const openAction = localize('debug.npm.notFound.open', 'Edit package.json');
165 if ((await vscode.window[method](message, openAction)) !== openAction) {
166 return;
167 }
168
169 // If the file exists, open it, otherwise create a new untitled file and
170 // fill it in with some minimal "scripts" section.
171 if (fs.existsSync(file)) {
172 const document = await vscode.workspace.openTextDocument(file);
173 await vscode.window.showTextDocument(document);
174 return;
175 }
176
177 const document = await vscode.workspace.openTextDocument(
178 vscode.Uri.file(file).with({ scheme: 'untitled' }),
179 );
180 const editor = await vscode.window.showTextDocument(document);
181 await editor.edit(e => e.insert(new vscode.Position(0, 0), defaultPackageJsonContents));
182 const pos = new vscode.Position(2, 5);
183 editor.selection = new vscode.Selection(pos, pos);
184}

Callers 1

findScriptsFunction · 0.85

Calls 4

withMethod · 0.80
fileMethod · 0.80
editMethod · 0.65
insertMethod · 0.65

Tested by

no test coverage detected