Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to handle vscode.openFolder command #6922

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { createUntitledResource } from '@theia/plugin-ext/lib/main/browser/edito
import { toDocumentSymbol } from '@theia/plugin-ext/lib/plugin/type-converters';
import { ViewColumn } from '@theia/plugin-ext/lib/plugin/types-impl';
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
import { WorkspaceService, WorkspaceInput } from '@theia/workspace/lib/browser/workspace-service';
import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { inject, injectable } from 'inversify';
Expand All @@ -45,6 +46,10 @@ export namespace VscodeCommands {
id: 'vscode.open'
};

export const OPEN_FOLDER: Command = {
id: 'vscode.openFolder'
};

export const DIFF: Command = {
id: 'vscode.diff'
};
Expand Down Expand Up @@ -74,6 +79,8 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
protected readonly mouseTracker: ApplicationShellMouseTracker;
@inject(PrefixQuickOpenService)
protected readonly quickOpen: PrefixQuickOpenService;
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(VscodeCommands.OPEN, {
Expand Down Expand Up @@ -101,6 +108,26 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
}
});

commands.registerCommand(VscodeCommands.OPEN_FOLDER, {
isVisible: () => false,
execute: async (resource: URI, forceNewWindow?: boolean) => {
if (!resource) {
throw new Error(`${VscodeCommands.OPEN_FOLDER.id} command requires at least URI argument.`);
}
if (!URI.isUri(resource)) {
throw new Error(`Invalid argument for ${VscodeCommands.OPEN_FOLDER.id} command with URI argument. Found ${resource}`);
}

let options: WorkspaceInput | undefined;
if (forceNewWindow) {
options = {
preserveWindow: forceNewWindow
};
}
this.workspaceService.open(new TheiaURI(resource), options);
}
});

commands.registerCommand(VscodeCommands.DIFF, {
isVisible: () => false,
// tslint:disable-next-line: no-any
Expand Down