From 27a169da4911d8fd11ee3ebd97f2ec314380cad3 Mon Sep 17 00:00:00 2001 From: FernandoAscencio Date: Tue, 7 Mar 2023 09:46:05 -0500 Subject: [PATCH] Part 2 Implementing similar to vscode --- .../plugin-vscode-commands-contribution.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts index 34d2f9fbdbe4b..d4043ff31909a 100755 --- a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts +++ b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts @@ -231,13 +231,21 @@ export class PluginVscodeCommandsContribution implements CommandContribution { isVisible: () => false, execute: async (resource: URI, columnOrOptions?: ViewColumn | TextDocumentShowOptions) => { try { - const result = await this.openWith(VscodeCommands.OPEN.id, resource, columnOrOptions); - if (!result) { - throw new Error(`Could not find an editor for ${resource}`); - } + await this.openWith(VscodeCommands.OPEN.id, resource, columnOrOptions); } catch (error) { - this.messageService.error(nls.localizeByDefault("Unable to open '{0}'", resource.path.toString())); - console.log(error.stack ? error.stack : error.toString()); + const message = nls.localizeByDefault("Unable to open '{0}'", resource.fsPath); + const createFile = 'Create File'; + this.messageService.error(message, createFile).then(async action => { + if (action === createFile) { + try { + await this.fileService.create(new TheiaURI(resource)); + await this.openWith(VscodeCommands.OPEN.id, resource, columnOrOptions); + } catch (e) { + this.messageService.error(e.message); + console.log(e.stack ? e.stack : e.toString()); + } + } + }); } } });