From 7182bc75acf68b4e722aedd0c7a4751b54c2e261 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 11 Jul 2024 23:21:31 -0500 Subject: [PATCH] chore: move quick pick instantiation (#1723) --- extensions/vscode/src/commands.ts | 15 ++++----------- .../vscode/src/extension/VsCodeExtension.ts | 12 ++++++++++-- .../vscode/src/quickEdit/QuickEditQuickPick.ts | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 1b17ced5f..1a897c9e2 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -169,6 +169,7 @@ const commandsMap: ( verticalDiffManager: VerticalPerLineDiffManager, continueServerClientPromise: Promise, battery: Battery, + quickEdit: QuickEdit, ) => { [command: string]: (...args: any) => any } = ( ide, extensionContext, @@ -178,6 +179,7 @@ const commandsMap: ( verticalDiffManager, continueServerClientPromise, battery, + quickEdit, ) => { /** * Streams an inline edit to the vertical diff manager. @@ -346,17 +348,6 @@ const commandsMap: ( }, "continue.quickEdit": async (initialPrompt?: string) => { captureCommandTelemetry("quickEdit"); - - const config = await configHandler.loadConfig(); - - const quickEdit = new QuickEdit( - verticalDiffManager, - config, - sidebar.webviewProtocol, - ide, - extensionContext, - ); - quickEdit.show(initialPrompt); }, "continue.writeCommentsForCode": async () => { @@ -693,6 +684,7 @@ export function registerAllCommands( verticalDiffManager: VerticalPerLineDiffManager, continueServerClientPromise: Promise, battery: Battery, + quickEdit: QuickEdit, ) { for (const [command, callback] of Object.entries( commandsMap( @@ -704,6 +696,7 @@ export function registerAllCommands( verticalDiffManager, continueServerClientPromise, battery, + quickEdit, ), )) { context.subscriptions.push( diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index f32e0ae4a..8c1cdef01 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -26,6 +26,7 @@ import { Battery } from "../util/battery"; import { TabAutocompleteModel } from "../util/loadAutocompleteModel"; import type { VsCodeWebviewProtocol } from "../webviewProtocol"; import { VsCodeMessenger } from "./VsCodeMessenger"; +import { QuickEdit } from "../quickEdit/QuickEditQuickPick"; export class VsCodeExtension { // Currently some of these are public so they can be used in testing (test/test-suites) @@ -54,8 +55,6 @@ export class VsCodeExtension { this.extensionContext = context; this.windowId = uuidv4(); - const ideSettings = this.ide.getIdeSettingsSync(); - // Dependencies of core let resolveVerticalDiffManager: any = undefined; const verticalDiffManagerPromise = new Promise( @@ -177,6 +176,14 @@ export class VsCodeExtension { context.subscriptions.push(this.battery); context.subscriptions.push(monitorBatteryChanges(this.battery)); + const quickEdit = new QuickEdit( + this.verticalDiffManager, + this.configHandler, + this.sidebar.webviewProtocol, + this.ide, + context, + ); + // Commands registerAllCommands( context, @@ -188,6 +195,7 @@ export class VsCodeExtension { this.verticalDiffManager, this.core.continueServerClientPromise, this.battery, + quickEdit, ); registerDebugTracker(this.sidebar.webviewProtocol, this.ide); diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index 742c0b95b..c95259dc5 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { ContinueConfig, IDE } from "core"; +import { IDE } from "core"; import * as vscode from "vscode"; import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; @@ -11,6 +11,7 @@ import { getModelQuickPickVal } from "./ModelSelectionQuickPick"; // @ts-ignore - error finding typings import MiniSearch from "minisearch"; +import { ConfigHandler } from "core/config/ConfigHandler"; /** * Used to track what action to take after a user interacts @@ -71,7 +72,7 @@ export class QuickEdit { constructor( private readonly verticalDiffManager: VerticalPerLineDiffManager, - private readonly config: ContinueConfig, + private readonly configHandler: ConfigHandler, private readonly webviewProtocol: VsCodeWebviewProtocol, private readonly ide: IDE, private readonly context: vscode.ExtensionContext, @@ -108,16 +109,18 @@ export class QuickEdit { * Gets the model title the user has chosen, or their default model */ private async _getCurModelTitle() { + const config = await this.configHandler.loadConfig(); + if (this._curModelTitle) { return this._curModelTitle; } let defaultModelTitle = - this.config.experimental?.modelRoles?.inlineEdit ?? + config.experimental?.modelRoles?.inlineEdit ?? (await this.webviewProtocol.request("getDefaultModelTitle", undefined)); if (!defaultModelTitle) { - defaultModelTitle = this.config.models[0]?.title!; + defaultModelTitle = config.models[0]?.title!; } return defaultModelTitle; @@ -345,6 +348,8 @@ export class QuickEdit { * Appends the entered prompt to the history and streams the edit with input and context. */ async show(initialPrompt?: string) { + const config = await this.configHandler.loadConfig(); + const selectedLabelOrInputVal = await this._getInitialQuickPickVal( initialPrompt, ); @@ -363,7 +368,7 @@ export class QuickEdit { case QuickEditInitialItemLabels.ContextProviders: const contextProviderVal = await getContextProviderQuickPickVal( - this.config, + config, this.ide, ); this.contextProviderStr = contextProviderVal ?? ""; @@ -375,9 +380,10 @@ export class QuickEdit { case QuickEditInitialItemLabels.Model: const curModelTitle = await this._getCurModelTitle(); + const selectedModelTitle = await getModelQuickPickVal( curModelTitle, - this.config, + config, ); if (selectedModelTitle) {