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

Implementing Terminal: Run Recent Commad when there are no open terminal #234124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TerminalContextKeys } from '../../../terminal/common/terminalContextKey
import { clearShellFileHistory, getCommandHistory, getDirectoryHistory } from '../common/history.js';
import { TerminalHistoryCommandId } from '../common/terminal.history.js';
import { showRunRecentQuickPick } from './terminalRunRecentQuickPick.js';
import { ICommandService } from '../../../../../platform/commands/common/commands.js';

// #region Terminal Contributions

Expand Down Expand Up @@ -66,13 +67,16 @@ class TerminalHistoryContribution extends Disposable implements ITerminalContrib
* Triggers a quick pick that displays recent commands or cwds. Selecting one will
* rerun it in the active terminal.
*/
async runRecent(type: 'command' | 'cwd', filterMode?: 'fuzzy' | 'contiguous', value?: string): Promise<void> {
async runRecent(type: 'command' | 'cwd', filterMode?: 'fuzzy' | 'contiguous', value?: string): Promise<void | boolean> {
const isFromRunRecentCommand = (type === 'command');

return this._instantiationService.invokeFunction(showRunRecentQuickPick,
this._ctx.instance,
this._terminalInRunCommandPicker,
type,
filterMode,
value,
isFromRunRecentCommand
);
}
}
Expand Down Expand Up @@ -121,7 +125,8 @@ registerActiveInstanceAction({
}
});

registerActiveInstanceAction({

registerTerminalAction({
id: TerminalHistoryCommandId.RunRecentCommand,
title: localize2('workbench.action.terminal.runRecentCommand', 'Run Recent Command...'),
precondition,
Expand All @@ -138,12 +143,24 @@ registerActiveInstanceAction({
weight: KeybindingWeight.WorkbenchContrib
}
],
run: async (activeInstance, c) => {
run: async (c, accessor) => {
let activeInstance = c.service.activeInstance;
if (!activeInstance) {
const commandService = accessor.get(ICommandService);
await commandService.executeCommand('workbench.action.terminal.new');
activeInstance = c.service.activeInstance!;
}
const history = TerminalHistoryContribution.get(activeInstance);
if (!history) {
return;
}
await history.runRecent('command');

let runRecentReturnValue: void | boolean = await history.runRecent('command');
for (let i = 0; i < 50 && runRecentReturnValue; i++) {
await new Promise(resolve => setTimeout(resolve, 100));
runRecentReturnValue = await history.runRecent('command');
}

if (activeInstance?.target === TerminalLocation.Editor) {
await c.editorService.revealActiveEditor();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function showRunRecentQuickPick(
type: 'command' | 'cwd',
filterMode?: 'fuzzy' | 'contiguous',
value?: string,
): Promise<void> {
isFromRunRecentCommand?: boolean,
): Promise<void | boolean> {
if (!instance.xterm) {
return;
}
Expand Down Expand Up @@ -228,6 +229,9 @@ export async function showRunRecentQuickPick(
}
}
if (items.length === 0) {
if (isFromRunRecentCommand) {
return true;
}
return;
}
const disposables = new DisposableStore();
Expand Down