Skip to content

Commit

Permalink
Prompt to create empty file for code command (closes #267)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Oct 2, 2021
1 parent 6f6e3ad commit 30c213a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Changes
- Proxy hop field now actually lists all known configs to pick from, instead of "TO DO" (#290)
- Remote `code` command (#267) now prompts to create an empty file for non-existing path

### Development changes
- Webpack setup has been improved quite a bit, mostly to clean up long ugly paths and make builds deterministic:
Expand Down
12 changes: 12 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export class ConnectionManager {
}
} catch (e) {
if (e instanceof vscode.FileSystemError) {
if (e.code === 'FileNotFound') {
logging.warning(`File '${absolutePath}' not found, prompting to create empty file`);
const choice = await vscode.window.showWarningMessage(`File '${absolutePath}' not found, create it?`, { modal: true }, 'Yes');
if (choice !== 'Yes') return;
try { await vscode.workspace.fs.writeFile(uri, Buffer.of()); } catch (e) {
logging.error(e);
vscode.window.showErrorMessage(`Failed to create an empty file at '${absolutePath}'`);
return;
}
await vscode.window.showTextDocument(uri);
return;
}
vscode.window.showErrorMessage(`Error opening ${absolutePath}: ${e.name.replace(/ \(FileSystemError\)/g, '')}`);
} else {
vscode.window.showErrorMessage(`Error opening ${absolutePath}: ${e.message || e}`);
Expand Down

0 comments on commit 30c213a

Please sign in to comment.