🤡 add remote config stubs

This commit is contained in:
Nate Sesti 2024-03-11 20:16:01 -07:00
parent 429d57cb3b
commit 3a75dbfe60
6 changed files with 15 additions and 156 deletions

View file

@ -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]}"`,
);
}
});
}

View file

@ -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();

View file

@ -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(

View file

@ -0,0 +1 @@
export async function setupRemoteConfigSync(reloadConfig: () => void) {}

View file

@ -0,0 +1,3 @@
export async function getUserToken(): Promise<string> {
return Promise.resolve("");
}

View file

@ -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<string | null>("userToken", null);
const remoteConfigServerUrl = settings.get<string | null>(
"remoteConfigServerUrl",
null,
);
const remoteConfigSyncPeriod = settings.get<number>(
"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}`);
}
}
}