diff --git a/core/config/load.ts b/core/config/load.ts index f911b9932..d0df1aa06 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -51,10 +51,12 @@ function resolveSerializedConfig(filepath: string): SerializedContinueConfig { }; config.env.forEach((envVar) => { - content = content.replaceAll( - new RegExp(`"${envVar}"`, "g"), - `"${env[envVar]}"`, - ); + if (envVar in env) { + content = content.replaceAll( + new RegExp(`"${envVar}"`, "g"), + `"${env[envVar]}"`, + ); + } }); } diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index 558096b14..3de6b77be 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -7,7 +7,6 @@ import { VsCodeExtension } from "../extension/vscodeExtension"; import registerQuickFixProvider from "../lang-server/codeActions"; import { getExtensionVersion } from "../util/util"; import { getExtensionUri } from "../util/vscode"; -import { ManualTokenAuthProvider } from "./auth"; import { setupInlineTips } from "./inlineTips"; export async function showTutorial() { @@ -68,17 +67,6 @@ function showRefactorMigrationMessage( } export async function activateExtension(context: vscode.ExtensionContext) { - const authProvider = vscode.authentication.registerAuthenticationProvider( - "manualToken", - "Continue Manual Token", - new ManualTokenAuthProvider(() => { - return new vscode.Disposable(() => {}); - }, context), - ); - const session = await vscode.authentication.getSession("manualToken", [], { - createIfNone: true, - }); - // Add necessary files getTsConfigPath(); diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index d06a3bc5a..36f8cafc4 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -11,8 +11,8 @@ import { DiffManager } from "../diff/horizontal"; import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager"; import { VsCodeIde } from "../ideProtocol"; import { registerAllCodeLensProviders } from "../lang-server/codeLens"; +import { setupRemoteConfigSync } from "../stubs/activation"; import { TabAutocompleteModel } from "../util/loadAutocompleteModel"; -import { RemoteConfigSync } from "../util/remoteConfig"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; export class VsCodeExtension { @@ -78,14 +78,10 @@ export class VsCodeExtension { this.extensionContext, this.verticalDiffManager, ); - try { - const configSync = new RemoteConfigSync( - this.configHandler.reloadConfig.bind(this.configHandler), - ); - configSync.setup(); - } catch (e) { - console.warn(`Failed to sync remote config: ${e}`); - } + + setupRemoteConfigSync( + this.configHandler.reloadConfig.bind(this.configHandler), + ); // Sidebar context.subscriptions.push( diff --git a/extensions/vscode/src/stubs/activation.ts b/extensions/vscode/src/stubs/activation.ts new file mode 100644 index 000000000..3e4ae2635 --- /dev/null +++ b/extensions/vscode/src/stubs/activation.ts @@ -0,0 +1 @@ +export async function setupRemoteConfigSync(reloadConfig: () => void) {} diff --git a/extensions/vscode/src/stubs/auth.ts b/extensions/vscode/src/stubs/auth.ts new file mode 100644 index 000000000..70de9e24b --- /dev/null +++ b/extensions/vscode/src/stubs/auth.ts @@ -0,0 +1,3 @@ +export async function getUserToken(): Promise { + return Promise.resolve(""); +} diff --git a/extensions/vscode/src/util/remoteConfig.ts b/extensions/vscode/src/util/remoteConfig.ts deleted file mode 100644 index 294277484..000000000 --- a/extensions/vscode/src/util/remoteConfig.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { - getConfigJsPathForRemote, - getConfigJsonPathForRemote, -} from "core/util/paths"; -import * as fs from "fs"; -import * as vscode from "vscode"; - -export class RemoteConfigSync { - private userToken: string | null; - private remoteConfigServerUrl: string | null; - private remoteConfigSyncPeriod: number; - - private syncInterval: NodeJS.Timer | undefined = undefined; - - constructor(private triggerReloadConfig: () => void) { - const { userToken, remoteConfigServerUrl, remoteConfigSyncPeriod } = - this.loadVsCodeSettings(); - this.userToken = userToken; - this.remoteConfigServerUrl = remoteConfigServerUrl; - this.remoteConfigSyncPeriod = remoteConfigSyncPeriod; - - // Listen for changes to VS Code settings, then trigger a refresh - vscode.workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration("continue")) { - const { userToken, remoteConfigServerUrl, remoteConfigSyncPeriod } = - this.loadVsCodeSettings(); - if ( - userToken !== this.userToken || - remoteConfigServerUrl !== this.remoteConfigServerUrl || - remoteConfigSyncPeriod !== this.remoteConfigSyncPeriod - ) { - this.userToken = userToken; - this.remoteConfigServerUrl = remoteConfigServerUrl; - this.remoteConfigSyncPeriod = remoteConfigSyncPeriod; - - this.setInterval(); - } - } - }); - } - - private loadVsCodeSettings() { - const settings = vscode.workspace.getConfiguration("continue"); - const userToken = settings.get("userToken", null); - const remoteConfigServerUrl = settings.get( - "remoteConfigServerUrl", - null, - ); - const remoteConfigSyncPeriod = settings.get( - "remoteConfigSyncPeriod", - 60, - ); - - return { - userToken, - remoteConfigServerUrl, - remoteConfigSyncPeriod, - }; - } - - async setup() { - if ( - this.userToken === null || - this.remoteConfigServerUrl === null || - this.remoteConfigServerUrl.trim() === "" - ) { - return; - } - if (!URL.canParse(this.remoteConfigServerUrl)) { - vscode.window.showErrorMessage( - "The value set for 'remoteConfigServerUrl' is not valid: ", - this.remoteConfigServerUrl, - ); - return; - } - - // Sync once - await this.sync(this.userToken, new URL(this.remoteConfigServerUrl)); - - // Set timer to sync at user-defined interval - this.setInterval(); - } - - private setInterval() { - if (this.syncInterval !== undefined) { - clearInterval(this.syncInterval); - } - this.syncInterval = setInterval( - () => { - if (!this.userToken || !this.remoteConfigServerUrl) return; - this.sync(this.userToken, new URL(this.remoteConfigServerUrl)); - }, - this.remoteConfigSyncPeriod * 1000 * 60, - ); - } - - async sync(userToken: string, remoteConfigServerUrl: URL) { - try { - const response = await fetch( - new URL("sync", remoteConfigServerUrl).href, - { - method: "GET", - headers: { - Authorization: `Bearer ${userToken}`, - }, - }, - ); - - if (!response.ok) { - vscode.window.showErrorMessage( - `Failed to sync remote config (HTTP ${response.status}): ${response.statusText}`, - ); - return; - } - - const { configJson, configJs } = await response.json(); - - fs.writeFileSync( - getConfigJsonPathForRemote(remoteConfigServerUrl), - configJson, - ); - fs.writeFileSync( - getConfigJsPathForRemote(remoteConfigServerUrl), - configJs, - ); - this.triggerReloadConfig(); - } catch (e) { - vscode.window.showErrorMessage(`Failed to sync remote config: ${e}`); - } - } -}