From 30c213ab31377a48db1b0416fd8ca5f3f6055f4d Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Sun, 26 Sep 2021 23:29:23 +0200 Subject: [PATCH] Prompt to create empty file for `code` command (closes #267) --- CHANGELOG.md | 1 + src/connection.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed6036..c95ebd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/src/connection.ts b/src/connection.ts index a9f6cc3..9feeacd 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -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}`);