Allow reusing specific terminal in Ide.runCommand

Signed-off-by: Fred Bricon <fbricon@gmail.com>
This commit is contained in:
Fred Bricon 2025-01-08 20:02:01 +01:00
parent 8296cd10ac
commit 3e09a43856
6 changed files with 31 additions and 13 deletions

9
core/index.d.ts vendored
View file

@ -630,7 +630,7 @@ export interface IDE {
openUrl(url: string): Promise<void>;
runCommand(command: string): Promise<void>;
runCommand(command: string, options?: TerminalOptions): Promise<void>;
saveFile(fileUri: string): Promise<void>;
@ -1230,4 +1230,9 @@ export type PackageDocsResult = {
} & (
| { error: string; details?: never }
| { details: PackageDetailsSuccess; error?: never }
);
);
export interface TerminalOptions {
reuseTerminal?: boolean,
terminalName?: string,
}

View file

@ -14,6 +14,7 @@ import type {
Range,
RangeInFile,
Thread,
TerminalOptions
} from "../";
export interface GetGhTokenArgs {
@ -28,7 +29,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
showVirtualFile: [{ name: string; content: string }, void];
openFile: [{ path: string }, void];
openUrl: [string, void];
runCommand: [{ command: string }, void];
runCommand: [{ command: string, options?: TerminalOptions }, void];
getSearchResults: [{ query: string }, string];
subprocess: [{ command: string; cwd?: string }, [string, string]];
saveFile: [{ filepath: string }, void];

View file

@ -13,6 +13,7 @@ import type {
Problem,
Range,
RangeInFile,
TerminalOptions,
Thread,
} from "../..";
@ -151,8 +152,8 @@ export class MessageIde implements IDE {
await this.request("openUrl", url);
}
async runCommand(command: string): Promise<void> {
await this.request("runCommand", { command });
async runCommand(command: string, options?: TerminalOptions): Promise<void> {
await this.request("runCommand", { command, options });
}
async saveFile(fileUri: string): Promise<void> {

View file

@ -13,6 +13,7 @@ import {
Problem,
Range,
RangeInFile,
TerminalOptions,
Thread,
ToastType,
} from "../index.js";
@ -190,7 +191,7 @@ class FileSystemIde implements IDE {
return Promise.resolve();
}
runCommand(command: string): Promise<void> {
runCommand(command: string, options?: TerminalOptions): Promise<void> {
return Promise.resolve();
}

View file

@ -33,6 +33,9 @@ export async function startLocalOllama(ide: IDE): Promise<void> {
}
}
if (startCommand) {
return ide.runCommand(startCommand);
return ide.runCommand(startCommand, {
reuseTerminal: true,
terminalName: "Start Ollama"
});
}
}

View file

@ -25,6 +25,7 @@ import type {
Location,
Problem,
RangeInFile,
TerminalOptions,
Thread,
} from "core";
@ -398,12 +399,18 @@ class VsCodeIde implements IDE {
);
}
async runCommand(command: string): Promise<void> {
let terminal : vscode.Terminal | undefined;
if (vscode.window.terminals.length) {
terminal = vscode.window.activeTerminal ?? vscode.window.terminals[0];
} else {
terminal = vscode.window.createTerminal();
async runCommand(command: string, options: TerminalOptions = {reuseTerminal: true}): Promise<void> {
let terminal: vscode.Terminal | undefined;
if (vscode.window.terminals.length && options.reuseTerminal) {
if (options.terminalName) {
terminal = vscode.window.terminals.find(t => t?.name === options.terminalName);
} else {
terminal = vscode.window.activeTerminal ?? vscode.window.terminals[0];
}
}
if( !terminal) {
terminal = vscode.window.createTerminal(options?.terminalName);
}
terminal.show();
terminal.sendText(command, false);