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

Move terminal dir/cwd history into terminalContrib/ #230236

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move most of history into terminalContrib
Part of #230129
  • Loading branch information
Tyriar committed Oct 1, 2024
commit 7ee03be5d152e53f73b5b9a28e2fc3e51ed67844
6 changes: 0 additions & 6 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,12 +1035,6 @@ export interface ITerminalInstance extends IBaseTerminalInstance {
*/
changeColor(color?: string, skipQuickPick?: boolean): Promise<string | undefined>;

/**
* Triggers a quick pick that displays recent commands or cwds. Selecting one will
* rerun it in the active terminal.
*/
runRecent(type: 'command' | 'cwd'): Promise<void>;

/**
* Attempts to detect and kill the process listening on specified port.
* If successful, places commandToRun on the command line
Expand Down
62 changes: 0 additions & 62 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { AbstractVariableResolverService } from '../../../services/configuration
import { ITerminalQuickPickItem } from './terminalProfileQuickpick.js';
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
import { getIconId, getColorClass, getUriClasses } from './terminalIcon.js';
import { clearShellFileHistory, getCommandHistory } from '../common/history.js';
import { IModelService } from '../../../../editor/common/services/model.js';
import { ILanguageService } from '../../../../editor/common/languages/language.js';
import { CancellationToken } from '../../../../base/common/cancellation.js';
Expand Down Expand Up @@ -433,33 +432,6 @@ export function registerTerminalActions() {
}
});

registerActiveInstanceAction({
id: TerminalCommandId.RunRecentCommand,
title: localize2('workbench.action.terminal.runRecentCommand', 'Run Recent Command...'),
precondition: sharedWhenClause.terminalAvailable,
keybinding: [
{
primary: KeyMod.CtrlCmd | KeyCode.KeyR,
when: ContextKeyExpr.and(CONTEXT_ACCESSIBILITY_MODE_ENABLED, ContextKeyExpr.or(TerminalContextKeys.focus, ContextKeyExpr.and(accessibleViewIsShown, accessibleViewCurrentProviderId.isEqualTo(AccessibleViewProviderId.Terminal)))),
weight: KeybindingWeight.WorkbenchContrib
},
{
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyR,
mac: { primary: KeyMod.WinCtrl | KeyMod.Alt | KeyCode.KeyR },
when: ContextKeyExpr.and(TerminalContextKeys.focus, CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
weight: KeybindingWeight.WorkbenchContrib
}
],
run: async (activeInstance, c) => {
await activeInstance.runRecent('command');
if (activeInstance?.target === TerminalLocation.Editor) {
await c.editorService.revealActiveEditor();
} else {
await c.groupService.showPanel(false);
}
}
});

registerActiveInstanceAction({
id: TerminalCommandId.CopyLastCommand,
title: localize2('workbench.action.terminal.copyLastCommand', "Copy Last Command"),
Expand Down Expand Up @@ -520,29 +492,6 @@ export function registerTerminalActions() {
}
});


registerActiveInstanceAction({
id: TerminalCommandId.GoToRecentDirectory,
title: localize2('workbench.action.terminal.goToRecentDirectory', 'Go to Recent Directory...'),
metadata: {
description: localize2('goToRecentDirectory.metadata', 'Goes to a recent folder'),
},
precondition: sharedWhenClause.terminalAvailable,
keybinding: {
primary: KeyMod.CtrlCmd | KeyCode.KeyG,
when: TerminalContextKeys.focus,
weight: KeybindingWeight.WorkbenchContrib
},
run: async (activeInstance, c) => {
await activeInstance.runRecent('cwd');
if (activeInstance?.target === TerminalLocation.Editor) {
await c.editorService.revealActiveEditor();
} else {
await c.groupService.showPanel(false);
}
}
});

registerTerminalAction({
id: TerminalCommandId.ResizePaneLeft,
title: localize2('workbench.action.terminal.resizePaneLeft', 'Resize Terminal Left'),
Expand Down Expand Up @@ -1502,17 +1451,6 @@ export function registerTerminalActions() {
},
run: (instance) => instance.toggleSizeToContentWidth()
});

registerTerminalAction({
id: TerminalCommandId.ClearPreviousSessionHistory,
title: localize2('workbench.action.terminal.clearPreviousSessionHistory', 'Clear Previous Session History'),
precondition: sharedWhenClause.terminalAvailable,
run: async (c, accessor) => {
getCommandHistory(accessor).clear();
clearShellFileHistory();
}
});

// Some commands depend on platform features
if (BrowserFeatures.clipboard.writeText) {
registerActiveXtermAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ITerminalContributionDescription = { readonly id: string } & (
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(instance: ITerminalInstance, processManager: ITerminalProcessManager, widgetManager: TerminalWidgetManager, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals?: false): void;
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(instance: ITerminalInstance, processManager: ITerminalProcessInfo, widgetManager: TerminalWidgetManager, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals: true): void;
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(instance: ITerminalInstance, processManager: ITerminalProcessManager, widgetManager: TerminalWidgetManager, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals = false): void {
// eslint-disable-next-line local/code-no-dangerous-type-assertions
// TODO: Pass in a context object containing instance, process manager, widgetmanager
TerminalContributionRegistry.INSTANCE.registerTerminalContribution({ id, ctor, canRunInDetachedTerminals } as ITerminalContributionDescription);
}

Expand Down
27 changes: 10 additions & 17 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ import { TerminalEditorInput } from './terminalEditorInput.js';
import { TerminalExtensionsRegistry } from './terminalExtensions.js';
import { getColorClass, createColorStyleElement, getStandardColors } from './terminalIcon.js';
import { TerminalProcessManager } from './terminalProcessManager.js';
import { showRunRecentQuickPick } from './terminalRunRecentQuickPick.js';
import { ITerminalStatusList, TerminalStatus, TerminalStatusList } from './terminalStatusList.js';
import { getTerminalResourcesFromDragEvent, getTerminalUri } from './terminalUri.js';
import { TerminalWidgetManager } from './widgets/widgetManager.js';
import { LineDataEventAddon } from './xterm/lineDataEventAddon.js';
import { XtermTerminal, getXtermScaledDimensions } from './xterm/xtermTerminal.js';
import { IEnvironmentVariableInfo } from '../common/environmentVariable.js';
import { getCommandHistory, getDirectoryHistory } from '../common/history.js';
import { getDirectoryHistory } from '../common/history.js';
import { DEFAULT_COMMANDS_TO_SKIP_SHELL, ITerminalProcessManager, ITerminalProfileResolverService, ProcessState, TERMINAL_CREATION_COMMANDS, TERMINAL_VIEW_ID, TerminalCommandId } from '../common/terminal.js';
import { TERMINAL_BACKGROUND_COLOR } from '../common/terminalColorRegistry.js';
import { TerminalContextKeys } from '../common/terminalContextKey.js';
Expand Down Expand Up @@ -362,7 +361,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

constructor(
private readonly _terminalShellTypeContextKey: IContextKey<string>,
private readonly _terminalInRunCommandPicker: IContextKey<boolean>,
private _shellLaunchConfig: IShellLaunchConfig,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
Expand Down Expand Up @@ -450,6 +448,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._terminalShellIntegrationEnabledContextKey = TerminalContextKeys.terminalShellIntegrationEnabled.bindTo(scopedContextKeyService);

this._logService.trace(`terminalInstance#ctor (instanceId: ${this.instanceId})`, this._shellLaunchConfig);
this._register(this.capabilities.onDidAddCapabilityType(e => this._logService.debug('terminalInstance added capability', e)));
this._register(this.capabilities.onDidRemoveCapabilityType(e => this._logService.debug('terminalInstance removed capability', e)));
this._register(this.capabilities.onDidAddCapabilityType(e => {
this._logService.debug('terminalInstance added capability', e);
if (e === TerminalCapability.CwdDetection) {
Expand All @@ -458,16 +458,15 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._setTitle(this.title, TitleEventSource.Config);
this._scopedInstantiationService.invokeFunction(getDirectoryHistory)?.add(e, { remoteAuthority: this.remoteAuthority });
});
} else if (e === TerminalCapability.CommandDetection) {
const commandCapability = this.capabilities.get(TerminalCapability.CommandDetection);
commandCapability?.onCommandFinished(e => {
if (e.command.trim().length > 0) {
this._scopedInstantiationService.invokeFunction(getCommandHistory)?.add(e.command, { shellType: this._shellType });
}
});
// } else if (e === TerminalCapability.CommandDetection) {
// const commandCapability = this.capabilities.get(TerminalCapability.CommandDetection);
// commandCapability?.onCommandFinished(e => {
// if (e.command.trim().length > 0) {
// this._scopedInstantiationService.invokeFunction(getCommandHistory)?.add(e.command, { shellType: this._shellType });
// }
// });
}
}));
this._register(this.capabilities.onDidRemoveCapabilityType(e => this._logService.debug('terminalInstance removed capability', e)));

// Resolve just the icon ahead of time so that it shows up immediately in the tabs. This is
// disabled in remote because this needs to be sync and the OS may differ on the remote
Expand Down Expand Up @@ -898,12 +897,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
await this.sendText(commandLine, shouldExecute, !shouldExecute);
}

async runRecent(type: 'command' | 'cwd', filterMode?: 'fuzzy' | 'contiguous', value?: string): Promise<void> {
return this._scopedInstantiationService.invokeFunction(
showRunRecentQuickPick, this, this._terminalInRunCommandPicker, type, filterMode, value
);
}

detachFromElement(): void {
this._wrapperElement.remove();
this._container = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { promiseWithResolvers } from '../../../../base/common/async.js';
export class TerminalInstanceService extends Disposable implements ITerminalInstanceService {
declare _serviceBrand: undefined;
private _terminalShellTypeContextKey: IContextKey<string>;
private _terminalInRunCommandPicker: IContextKey<boolean>;
private _backendRegistration = new Map<string | undefined, { promise: Promise<void>; resolve: () => void }>();

private readonly _onDidCreateInstance = this._register(new Emitter<ITerminalInstance>());
Expand All @@ -36,7 +35,6 @@ export class TerminalInstanceService extends Disposable implements ITerminalInst
) {
super();
this._terminalShellTypeContextKey = TerminalContextKeys.shellType.bindTo(this._contextKeyService);
this._terminalInRunCommandPicker = TerminalContextKeys.inTerminalRunCommandPicker.bindTo(this._contextKeyService);

for (const remoteAuthority of [undefined, environmentService.remoteAuthority]) {
const { promise, resolve } = promiseWithResolvers<void>();
Expand All @@ -48,11 +46,7 @@ export class TerminalInstanceService extends Disposable implements ITerminalInst
createInstance(shellLaunchConfig: IShellLaunchConfig, target: TerminalLocation): ITerminalInstance;
createInstance(config: IShellLaunchConfig | ITerminalProfile, target: TerminalLocation): ITerminalInstance {
const shellLaunchConfig = this.convertProfileToShellLaunchConfig(config);
const instance = this._instantiationService.createInstance(TerminalInstance,
this._terminalShellTypeContextKey,
this._terminalInRunCommandPicker,
shellLaunchConfig
);
const instance = this._instantiationService.createInstance(TerminalInstance, this._terminalShellTypeContextKey, shellLaunchConfig);
instance.target = target;
this._onDidCreateInstance.fire(instance);
return instance;
Expand Down
Loading