Skip to content

Commit

Permalink
Attempt to use correct workspace for remote terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Apr 20, 2023
1 parent 39da375 commit 9e4fa31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/vs/server/node/remoteTerminalChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { withNullAsUndefined } from 'vs/base/common/types';
import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver';

class CustomVariableResolver extends AbstractVariableResolverService {
constructor(
Expand Down Expand Up @@ -238,8 +239,9 @@ export class RemoteTerminalChannel extends Disposable implements IServerChannel<
}
const envVariableCollections = new Map<string, IEnvironmentVariableCollection>(entries);
const mergedCollection = new MergedEnvironmentVariableCollection(envVariableCollections);
const cwdWorkspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, { getWorkspaceFolder: args.getWorkspaceFolder }, undefined);
const workspaceFolder = activeWorkspaceFolder ? withNullAsUndefined(activeWorkspaceFolder) : undefined;
await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver);
await mergedCollection.applyToProcessEnvironment(env, { workspaceFolder: cwdWorkspaceFolder ?? workspaceFolder }, variableResolver);
}

// Fork the process and listen for messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { serializeEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariableShared';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor';
Expand Down Expand Up @@ -51,6 +51,8 @@ export interface ICreateTerminalProcessArguments {
rows: number;
unicodeVersion: '6' | '11';
resolverEnv: { [key: string]: string | null } | undefined;
// TODO: Remove this when last active workspace is fixed
getWorkspaceFolder: (resource: URI) => IWorkspaceFolder | null;
}

export interface ICreateTerminalProcessResult {
Expand Down Expand Up @@ -182,7 +184,8 @@ export class RemoteTerminalChannelClient implements IPtyHostController {
cols,
rows,
unicodeVersion,
resolverEnv
resolverEnv,
getWorkspaceFolder: this._workspaceContextService.getWorkspaceFolder.bind(this._workspaceContextService),
};
return await this._channel.call<ICreateTerminalProcessResult>('$createProcess', args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import { withNullAsUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { IHistoryService } from 'vs/workbench/services/history/common/history';

export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined {
export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: { getWorkspaceFolder(resource: URI): IWorkspaceFolder | null }, historyService: IHistoryService | undefined): IWorkspaceFolder | undefined {
const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd;
let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined;
if (!workspaceFolder) {
// fallback to last active workspace if cwd is not available or it is not in workspace
// TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot();
const activeWorkspaceRootUri = historyService?.getLastActiveWorkspaceRoot();
workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
}
return workspaceFolder;
Expand Down

0 comments on commit 9e4fa31

Please sign in to comment.