Skip to content

Commit

Permalink
Support terminal.integrated.cwd as a resource scope setting
Browse files Browse the repository at this point in the history
Fixes #42165
  • Loading branch information
Tyriar committed Oct 11, 2021
1 parent a9bcd45 commit 897ed30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { isAbsolute } from 'vs/base/common/path';

export const switchTerminalActionViewItemSeparator = '─────────';
export const switchTerminalShowTabsTitle = localize('showTerminalTabs', "Show Tabs");
Expand Down Expand Up @@ -1650,6 +1651,7 @@ export function registerTerminalActions() {
const terminalGroupService = accessor.get(ITerminalGroupService);
const workspaceContextService = accessor.get(IWorkspaceContextService);
const commandService = accessor.get(ICommandService);
const configurationService = accessor.get(IConfigurationService);
const folders = workspaceContextService.getWorkspace().folders;
if (eventOrOptions && eventOrOptions instanceof MouseEvent && (eventOrOptions.altKey || eventOrOptions.ctrlKey)) {
const activeInstance = terminalService.activeInstance;
Expand All @@ -1672,12 +1674,23 @@ export function registerTerminalActions() {
const options: IPickOptions<IQuickPickItem> = {
placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal")
};
const workspace = await commandService.executeCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
const workspace = await commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
if (!workspace) {
// Don't create the instance if the workspace picker was canceled
return;
}
eventOrOptions.cwd = workspace.uri;
const cwdConfig = configurationService.getValue(TerminalSettingId.Cwd, { resource: workspace.uri });
if (typeof cwdConfig === 'string' && cwdConfig.length > 0) {
if (isAbsolute(cwdConfig)) {
eventOrOptions.cwd = URI.from({
scheme: workspace.uri.scheme,
path: cwdConfig
});
} else {
eventOrOptions.cwd = URI.joinPath(workspace.uri, cwdConfig);
}
}
instance = await terminalService.createTerminal(eventOrOptions);
}
terminalService.setActiveInstance(instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Extensions, IConfigurationNode, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationScope, Extensions, IConfigurationNode, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { localize } from 'vs/nls';
import { DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, TerminalCursorStyle, DEFAULT_COMMANDS_TO_SKIP_SHELL, SUGGESTIONS_FONT_WEIGHT, MINIMUM_FONT_WEIGHT, MAXIMUM_FONT_WEIGHT, DEFAULT_LOCAL_ECHO_EXCLUDE } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalLocationString, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
Expand Down Expand Up @@ -297,7 +297,8 @@ const terminalConfiguration: IConfigurationNode = {
restricted: true,
description: localize('terminal.integrated.cwd', "An explicit start path where the terminal will be launched, this is used as the current working directory (cwd) for the shell process. This may be particularly useful in workspace settings if the root directory is not a convenient cwd."),
type: 'string',
default: undefined
default: undefined,
scope: ConfigurationScope.RESOURCE
},
[TerminalSettingId.ConfirmOnExit]: {
description: localize('terminal.integrated.confirmOnExit', "Controls whether to confirm when the window closes if there are active terminal sessions."),
Expand Down

1 comment on commit 897ed30

@stevenjoezhang
Copy link
Contributor

@stevenjoezhang stevenjoezhang commented on 897ed30 Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Tyriar, isAbsolute(cwdConfig) may not be accurate here. cwdConfig could be something like ${fileDirname} or ${workspaceFolder}, it will be replaced with an absolute path later:

const initialCwd = terminalEnvironment.getCwd(
shellLaunchConfig,
userHome,
variableResolver,
activeWorkspaceRootUri,
this._configHelper.config.cwd,
this._logService
);

but the value of isAbsolute(cwdConfig) in line 1685 is false. So, the URI.joinPath in line 1691 will actually join two absolute path, the result is like D:\sources\app\scripts\D:\sources\app\scripts which is invalid. See #136099

Please sign in to comment.