mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
inherit split cwd for all cases (#141020)
This commit is contained in:
parent
f7baac67c1
commit
cfa23d7d7e
|
@ -50,4 +50,3 @@ preexec() {
|
|||
update_prompt
|
||||
PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'precmd'
|
||||
trap 'preexec' DEBUG
|
||||
update_cwd
|
||||
|
|
|
@ -49,4 +49,3 @@ preexec() {
|
|||
}
|
||||
precmd_functions+=($precmd_functions precmd)
|
||||
preexec_functions+=($preexec_functions preexec)
|
||||
update_cwd
|
||||
|
|
|
@ -1553,8 +1553,7 @@ export function registerTerminalActions() {
|
|||
for (const t of instances) {
|
||||
terminalService.setActiveInstance(t);
|
||||
terminalService.doWithActiveInstance(async instance => {
|
||||
const cwd = await getCwdForSplit(terminalService.configHelper, instance);
|
||||
await terminalService.createTerminal({ location: { parentTerminal: instance }, cwd });
|
||||
await terminalService.createTerminal({ location: { parentTerminal: instance } });
|
||||
await terminalGroupService.showPanel(true);
|
||||
});
|
||||
}
|
||||
|
@ -1680,8 +1679,7 @@ export function registerTerminalActions() {
|
|||
const terminalService = accessor.get(ITerminalService);
|
||||
const terminalGroupService = accessor.get(ITerminalGroupService);
|
||||
await terminalService.doWithActiveInstance(async t => {
|
||||
const cwd = await getCwdForSplit(terminalService.configHelper, t);
|
||||
const instance = await terminalService.createTerminal({ location: { parentTerminal: t }, cwd });
|
||||
const instance = await terminalService.createTerminal({ location: { parentTerminal: t } });
|
||||
if (instance?.target !== TerminalLocation.Editor) {
|
||||
await terminalGroupService.showPanel(true);
|
||||
}
|
||||
|
@ -1746,13 +1744,9 @@ export function registerTerminalActions() {
|
|||
const configurationService = accessor.get(IConfigurationService);
|
||||
const folders = workspaceContextService.getWorkspace().folders;
|
||||
if (eventOrOptions && eventOrOptions instanceof MouseEvent && (eventOrOptions.altKey || eventOrOptions.ctrlKey)) {
|
||||
const activeInstance = terminalService.activeInstance;
|
||||
if (activeInstance) {
|
||||
const cwd = await getCwdForSplit(terminalService.configHelper, activeInstance);
|
||||
await terminalService.createTerminal({ location: { parentTerminal: activeInstance }, cwd });
|
||||
await terminalService.createTerminal({ location: { splitActiveTerminal: true } });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (terminalService.isProcessSupportRegistered) {
|
||||
eventOrOptions = !eventOrOptions || eventOrOptions instanceof MouseEvent ? {} : eventOrOptions;
|
||||
|
@ -2268,8 +2262,7 @@ export function refreshTerminalActions(detectedProfiles: ITerminalProfile[]) {
|
|||
if (event && (event.altKey || event.ctrlKey)) {
|
||||
const parentTerminal = terminalService.activeInstance;
|
||||
if (parentTerminal) {
|
||||
cwd = await getCwdForSplit(terminalService.configHelper, parentTerminal);
|
||||
await terminalService.createTerminal({ location: { parentTerminal }, config: options?.config, cwd });
|
||||
await terminalService.createTerminal({ location: { parentTerminal }, config: options?.config });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ import { IKeyMods } from 'vs/base/parts/quickinput/common/quickInput';
|
|||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { getCwdForSplit } from 'vs/workbench/contrib/terminal/browser/terminalActions';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
||||
export class TerminalService implements ITerminalService {
|
||||
declare _serviceBrand: undefined;
|
||||
|
@ -153,7 +155,9 @@ export class TerminalService implements ITerminalService {
|
|||
@IEditorGroupsService private readonly _editorGroupsService: IEditorGroupsService,
|
||||
@ITerminalProfileService private readonly _terminalProfileService: ITerminalProfileService,
|
||||
@IExtensionService private readonly _extensionService: IExtensionService,
|
||||
@INotificationService private readonly _notificationService: INotificationService
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService,
|
||||
@ICommandService private readonly _commandService: ICommandService
|
||||
) {
|
||||
this._configHelper = this._instantiationService.createInstance(TerminalConfigHelper);
|
||||
// the below avoids having to poll routinely.
|
||||
|
@ -222,7 +226,6 @@ export class TerminalService implements ITerminalService {
|
|||
} else if (result.config && 'profileName' in result.config) {
|
||||
if (keyMods?.alt && activeInstance) {
|
||||
// create split, only valid if there's an active instance
|
||||
const cwd = await getCwdForSplit(this.configHelper, activeInstance);
|
||||
instance = await this.createTerminal({ location: { parentTerminal: activeInstance }, config: result.config, cwd });
|
||||
} else {
|
||||
instance = await this.createTerminal({ location: this.defaultLocation, config: result.config, cwd });
|
||||
|
@ -921,10 +924,13 @@ export class TerminalService implements ITerminalService {
|
|||
contributedProfile = await this._terminalProfileService.getContributedDefaultProfile(shellLaunchConfig);
|
||||
}
|
||||
|
||||
const splitActiveTerminal = typeof options?.location === 'object' && 'splitActiveTerminal' in options.location ? options.location.splitActiveTerminal : typeof options?.location === 'object' ? 'parentTerminal' in options.location : false;
|
||||
|
||||
this._updateCwdForSplit(shellLaunchConfig, splitActiveTerminal, options);
|
||||
|
||||
// Launch the contributed profile
|
||||
if (contributedProfile) {
|
||||
const resolvedLocation = this.resolveLocation(options?.location);
|
||||
const splitActiveTerminal = typeof options?.location === 'object' && 'splitActiveTerminal' in options.location ? options.location.splitActiveTerminal : typeof options?.location === 'object' ? 'parentTerminal' in options.location : false;
|
||||
let location: TerminalLocation | { viewColumn: number, preserveState?: boolean } | { splitActiveTerminal: boolean } | undefined;
|
||||
if (splitActiveTerminal) {
|
||||
location = resolvedLocation === TerminalLocation.Editor ? { viewColumn: SIDE_GROUP } : { splitActiveTerminal: true };
|
||||
|
@ -943,10 +949,6 @@ export class TerminalService implements ITerminalService {
|
|||
return instance;
|
||||
}
|
||||
|
||||
if (options?.cwd) {
|
||||
shellLaunchConfig.cwd = options.cwd;
|
||||
}
|
||||
|
||||
if (!shellLaunchConfig.customPtyImplementation && !this.isProcessSupportRegistered) {
|
||||
throw new Error('Could not create terminal when process support is not registered');
|
||||
}
|
||||
|
@ -970,6 +972,24 @@ export class TerminalService implements ITerminalService {
|
|||
return this._createTerminal(shellLaunchConfig, location, options);
|
||||
}
|
||||
|
||||
private async _updateCwdForSplit(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise<void> {
|
||||
let cwd = shellLaunchConfig.cwd;
|
||||
if (!cwd) {
|
||||
if (options?.cwd) {
|
||||
shellLaunchConfig.cwd = options.cwd;
|
||||
} else if (splitActiveTerminal && options?.location) {
|
||||
let parent = this.activeInstance;
|
||||
if (typeof options.location === 'object' && 'parentTerminal' in options.location) {
|
||||
parent = options.location.parentTerminal;
|
||||
}
|
||||
if (!parent) {
|
||||
throw new Error('Cannot split without an active instance');
|
||||
}
|
||||
shellLaunchConfig.cwd = await getCwdForSplit(this.configHelper, parent, this._workspaceContextService.getWorkspace().folders, this._commandService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _splitTerminal(shellLaunchConfig: IShellLaunchConfig, location: TerminalLocation, parent: ITerminalInstance): ITerminalInstance {
|
||||
let instance;
|
||||
// Use the URI from the base instance if it exists, this will correctly split local terminals
|
||||
|
|
|
@ -46,7 +46,6 @@ import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecy
|
|||
import { IProcessDetails } from 'vs/platform/terminal/common/terminalProcess';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
import { getTerminalResourcesFromDragEvent, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { getCwdForSplit } from 'vs/workbench/contrib/terminal/browser/terminalActions';
|
||||
|
||||
const $ = DOM.$;
|
||||
|
||||
|
@ -146,8 +145,7 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
|
|||
// unless multi-selection is in progress
|
||||
this.onMouseClick(async e => {
|
||||
if (e.browserEvent.altKey && e.element) {
|
||||
const cwd = await getCwdForSplit(this._terminalService.configHelper, e.element);
|
||||
await this._terminalService.createTerminal({ location: { parentTerminal: e.element }, cwd });
|
||||
await this._terminalService.createTerminal({ location: { parentTerminal: e.element } });
|
||||
} else if (this._getFocusMode() === 'singleClick') {
|
||||
if (this.getSelection().length <= 1) {
|
||||
e.element?.focus(true);
|
||||
|
@ -479,8 +477,7 @@ class TerminalTabsRenderer implements IListRenderer<ITerminalInstance, ITerminal
|
|||
const actions = [
|
||||
new Action(TerminalCommandId.SplitInstance, terminalStrings.split.short, ThemeIcon.asClassName(Codicon.splitHorizontal), true, async () => {
|
||||
this._runForSelectionOrInstance(instance, async e => {
|
||||
const cwd = await getCwdForSplit(this._terminalService.configHelper, e);
|
||||
this._terminalService.createTerminal({ location: { parentTerminal: e }, cwd });
|
||||
this._terminalService.createTerminal({ location: { parentTerminal: e } });
|
||||
});
|
||||
}),
|
||||
new Action(TerminalCommandId.KillInstance, terminalStrings.kill.short, ThemeIcon.asClassName(Codicon.trashcan), true, async () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { IContextMenuService, IContextViewService } from 'vs/platform/contextvie
|
|||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IThemeService, IColorTheme, registerThemingParticipant, ICssStyleCollector, ThemeIcon, Themable } from 'vs/platform/theme/common/themeService';
|
||||
import { getCwdForSplit, switchTerminalActionViewItemSeparator, switchTerminalShowTabsTitle } from 'vs/workbench/contrib/terminal/browser/terminalActions';
|
||||
import { switchTerminalActionViewItemSeparator, switchTerminalShowTabsTitle } from 'vs/workbench/contrib/terminal/browser/terminalActions';
|
||||
import { TERMINAL_BACKGROUND_COLOR, TERMINAL_BORDER_COLOR, TERMINAL_DRAG_AND_DROP_BACKGROUND, TERMINAL_TAB_ACTIVE_BORDER } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
|
||||
import { INotificationService, IPromptChoice, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { ICreateTerminalOptions, ITerminalGroupService, ITerminalInstance, ITerminalService, TerminalConnectionState } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
|
@ -196,8 +196,7 @@ export class TerminalViewPane extends ViewPane {
|
|||
run: async () => {
|
||||
const instance = this._terminalGroupService.activeInstance;
|
||||
if (instance) {
|
||||
const cwd = await getCwdForSplit(this._terminalService.configHelper, instance);
|
||||
const newInstance = await this._terminalService.createTerminal({ location: { parentTerminal: instance }, cwd });
|
||||
const newInstance = await this._terminalService.createTerminal({ location: { parentTerminal: instance } });
|
||||
return newInstance?.focusWhenReady();
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -95,9 +95,6 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
|
|||
if (!this.capabilities.has(TerminalCapability.CommandDetection)) {
|
||||
this.capabilities.add(TerminalCapability.CommandDetection, new CommandDetectionCapability());
|
||||
}
|
||||
if (!this.capabilities.has(TerminalCapability.CwdDetection)) {
|
||||
this.capabilities.add(TerminalCapability.CwdDetection, new CwdDetectionCapability());
|
||||
}
|
||||
case ShellIntegrationOscPt.CommandStart:
|
||||
type = ShellIntegrationInteraction.CommandStart;
|
||||
break;
|
||||
|
@ -123,6 +120,9 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
|
|||
const [type, info] = data.split('=');
|
||||
switch (type) {
|
||||
case ShellIntegrationInfo.CurrentDir:
|
||||
if (!this.capabilities.has(TerminalCapability.CwdDetection)) {
|
||||
this.capabilities.add(TerminalCapability.CwdDetection, new CwdDetectionCapability());
|
||||
}
|
||||
this.capabilities.get(TerminalCapability.CwdDetection)?.updateCwd(info);
|
||||
value = info;
|
||||
break;
|
||||
|
|
|
@ -13,7 +13,7 @@ export class CwdDetectionCapability {
|
|||
private readonly _onDidChangeCwd = new Emitter<string>();
|
||||
readonly onDidChangeCwd = this._onDidChangeCwd.event;
|
||||
|
||||
async getCwd(): Promise<string> {
|
||||
getCwd(): string {
|
||||
return this._cwd;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue