From 512ddd7242116d6e5d32a4520d30f5ba71e5dba9 Mon Sep 17 00:00:00 2001 From: FernandoAscencio Date: Tue, 7 Mar 2023 13:48:52 -0500 Subject: [PATCH] vscode: User Feedback with vscode.open command This commit finishes imlementations of #6568 This commit closes #5667 Signed-Off-By: FernandoAscencio --- .../plugin-vscode-commands-contribution.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 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 8a32c4303ba15..4978bec818243 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 @@ -14,7 +14,7 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 // ***************************************************************************** -import { Command, CommandContribution, CommandRegistry, environment, isOSX, CancellationTokenSource } from '@theia/core'; +import { Command, CommandContribution, CommandRegistry, environment, isOSX, CancellationTokenSource, MessageService } from '@theia/core'; import { ApplicationShell, CommonCommands, @@ -178,6 +178,8 @@ export class PluginVscodeCommandsContribution implements CommandContribution { protected readonly textModelService: MonacoTextModelService; @inject(WindowService) protected readonly windowService: WindowService; + @inject(MessageService) + protected readonly messageService: MessageService; private async openWith(commandId: string, resource: URI, columnOrOptions?: ViewColumn | TextDocumentShowOptions, openerId?: string): Promise { if (!resource) { @@ -228,9 +230,23 @@ export class PluginVscodeCommandsContribution implements CommandContribution { commands.registerCommand(VscodeCommands.OPEN, { isVisible: () => false, execute: async (resource: URI, columnOrOptions?: ViewColumn | TextDocumentShowOptions) => { - const result = await this.openWith(VscodeCommands.OPEN.id, resource, columnOrOptions); - if (!result) { - throw new Error(`Could not find an editor for ${resource}`); + try { + await this.openWith(VscodeCommands.OPEN.id, resource, columnOrOptions); + } catch (error) { + console.warn(error); + const message = nls.localizeByDefault("Unable to open '{0}'", resource.fsPath); + const createFile = nls.localizeByDefault('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) { + console.warn(e); + this.messageService.error(e.message); + } + } + }); } } });