Skip to content

Commit

Permalink
vscode: User Feedback with vscode.open command
Browse files Browse the repository at this point in the history
This commit finishes imlementations of eclipse-theia#6568
This commit closes eclipse-theia#5667

Signed-Off-By: FernandoAscencio <fernando.ascencio.cama@ericsson.com>
  • Loading branch information
FernandoAscencio committed Mar 7, 2023
1 parent a5e1162 commit 512ddd7
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<boolean> {
if (!resource) {
Expand Down Expand Up @@ -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);
}
}
});
}
}
});
Expand Down

0 comments on commit 512ddd7

Please sign in to comment.