Skip to content

Commit

Permalink
Use canonical URI when opening local terminal
Browse files Browse the repository at this point in the history
Fixes #128113
  • Loading branch information
Tyriar committed Jul 7, 2021
1 parent 2336e76 commit c8d0707
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { TERMINAL_ACTION_CATEGORY, TerminalCommandId } from 'vs/workbench/contri
import { Action } from 'vs/base/common/actions';
import { ITerminalGroupService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { URI } from 'vs/base/common/uri';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { Schemas } from 'vs/base/common/network';

export function registerRemoteContributions() {
const actionRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
Expand All @@ -25,13 +29,26 @@ export class CreateNewLocalTerminalAction extends Action {
id: string, label: string,
@ITerminalService private readonly _terminalService: ITerminalService,
@ITerminalGroupService private readonly _terminalGroupService: ITerminalGroupService,
@INativeEnvironmentService private readonly _nativeEnvironmentService: INativeEnvironmentService
@INativeEnvironmentService private readonly _nativeEnvironmentService: INativeEnvironmentService,
@IRemoteAuthorityResolverService private readonly _remoteAuthorityResolverService: IRemoteAuthorityResolverService,
@IHistoryService private readonly _historyService: IHistoryService
) {
super(id, label);
}

override run(): Promise<any> {
const instance = this._terminalService.createTerminal({ cwd: this._nativeEnvironmentService.userHome });
override async run(): Promise<any> {
let cwd: URI;
try {
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.vscodeRemote);
if (activeWorkspaceRootUri) {
cwd = await this._remoteAuthorityResolverService.getCanonicalURI(activeWorkspaceRootUri);

This comment has been minimized.

Copy link
@chrmarti

chrmarti Jul 8, 2021

Collaborator

@Tyriar Not all canonical URIs are local. It might make sense to check if it is a file: URI for opening a local terminal.

This comment has been minimized.

Copy link
@Tyriar

Tyriar Jul 8, 2021

Author Member

Thanks, fixed in b7ad12f

} else {
cwd = this._nativeEnvironmentService.userHome;
}
} catch {
cwd = this._nativeEnvironmentService.userHome;
}
const instance = this._terminalService.createTerminal({ cwd });
if (!instance) {
return Promise.resolve(undefined);
}
Expand Down

0 comments on commit c8d0707

Please sign in to comment.