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