diff --git a/core/index.d.ts b/core/index.d.ts index e4f3ff143..01fb4b5c0 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -630,7 +630,7 @@ export interface IDE { openUrl(url: string): Promise; - runCommand(command: string): Promise; + runCommand(command: string, options?: TerminalOptions): Promise; saveFile(fileUri: string): Promise; @@ -1230,4 +1230,9 @@ export type PackageDocsResult = { } & ( | { error: string; details?: never } | { details: PackageDetailsSuccess; error?: never } -); + ); + +export interface TerminalOptions { + reuseTerminal?: boolean, + terminalName?: string, +} diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index 4df3cb95b..8c0d2557c 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -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]; diff --git a/core/protocol/messenger/messageIde.ts b/core/protocol/messenger/messageIde.ts index 9f46602c1..aaa567f39 100644 --- a/core/protocol/messenger/messageIde.ts +++ b/core/protocol/messenger/messageIde.ts @@ -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 { - await this.request("runCommand", { command }); + async runCommand(command: string, options?: TerminalOptions): Promise { + await this.request("runCommand", { command, options }); } async saveFile(fileUri: string): Promise { diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 45ac7a7c5..b4297f7bc 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -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 { + runCommand(command: string, options?: TerminalOptions): Promise { return Promise.resolve(); } diff --git a/core/util/ollamaHelper.ts b/core/util/ollamaHelper.ts index 9520de678..936c6339b 100644 --- a/core/util/ollamaHelper.ts +++ b/core/util/ollamaHelper.ts @@ -33,6 +33,9 @@ export async function startLocalOllama(ide: IDE): Promise { } } if (startCommand) { - return ide.runCommand(startCommand); + return ide.runCommand(startCommand, { + reuseTerminal: true, + terminalName: "Start Ollama" + }); } } diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 457cd5985..2cec274e9 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -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 { - 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 { + 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);