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 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
15 changes: 13 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,22 @@ export function registerActiveInstanceAction(
const originalRun = options.run;
return registerTerminalAction({
...options,
run: (c, accessor, args) => {
const activeInstance = c.service.activeInstance;
run: async (c, accessor, args) => {
let activeInstance = c.service.activeInstance;
const id = options.id;
if (activeInstance) {
return originalRun(activeInstance, c, accessor, args);
}
if (id !== 'workbench.action.terminal.runRecentCommand') {
return;
}
const commandService = accessor.get(ICommandService);
await commandService.executeCommand('workbench.action.terminal.new');
activeInstance = c.service.activeInstance;
Copy link
Member

Choose a reason for hiding this comment

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

This is a generic function so you shouldn't be changing this, instead you should change the run callback passed in when it's called.

if (activeInstance) {
return originalRun(activeInstance, c, accessor, args);
}
return;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,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 @@ -143,7 +146,13 @@ registerActiveInstanceAction({
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