( method: 'showWarningMessage' | 'showErrorMessage', message: string, file: string, )
| 189 | const defaultPackageJsonContents = `{\n "scripts": {\n \n }\n}\n`; |
| 190 | |
| 191 | async 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 | } |
no test coverage detected