Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New extension settings #40

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
"type": "number",
"default": 2345
},
"dbos-ttdbg.debug_proxy_path": {
"type": "string",
"description": "Path to the debug proxy executable. Overrides downloading the latest version of the debug proxy."
},
"dbos-ttdbg.debug_proxy_launch": {
"type": "boolean",
"default": true,
"description": "Automatically launch the debug proxy when debugging."
},
"dbos-ttdbg.prov_db_database": {
"type": "string"
},
Expand Down
13 changes: 13 additions & 0 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const PROV_DB_DATABASE = "prov_db_database";
const PROV_DB_USER = "prov_db_user";
const DEBUG_PROXY_PORT = "debug_proxy_port";
const DEBUG_PRE_LAUNCH_TASK = "debug_pre_launch_task";
const DEBUG_PROXY_PATH = "debug_proxy_path";
const DEBUG_PROXY_LAUNCH = "debug_proxy_launch";

export function getLaunchProxyConfig() {
const cfg = vscode.workspace.getConfiguration(TTDBG_CONFIG_SECTION);
return cfg.get<boolean>(DEBUG_PROXY_LAUNCH, true);
}

export function getProxyPathConfig() {
const cfg = vscode.workspace.getConfiguration(TTDBG_CONFIG_SECTION);
const proxyPath = cfg.get<string>(DEBUG_PROXY_PATH);
return proxyPath ? vscode.Uri.file(proxyPath) : undefined;
}

export interface DbosDebugConfig {
user: string;
Expand Down
32 changes: 24 additions & 8 deletions src/debugProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as semver from 'semver';
import { CloudStorage } from './CloudStorage';
import { logger } from './extension';
import { exists } from './utility';
import { DbosDebugConfig } from './Configuration';
import { DbosDebugConfig, getLaunchProxyConfig, getProxyPathConfig } from './Configuration';

const IS_WINDOWS = process.platform === "win32";
const EXE_FILE_NAME = `debug-proxy${IS_WINDOWS ? ".exe" : ""}`;
Expand All @@ -19,11 +19,10 @@ function exeFileName(storageUri: vscode.Uri) {

const execFile = promisify(cpExecFile);

async function getLocalVersion(storageUri: vscode.Uri) {
const exeUri = exeFileName(storageUri);
if (!(await exists(exeUri))) {
return Promise.resolve(undefined);
}
async function getLocalVersion(exeUri: vscode.Uri) {
// if (!(await exists(exeUri))) {
// return Promise.resolve(undefined);
// }

try {
const { stdout } = await execFile(exeUri.fsPath, ["-version"]);
Expand Down Expand Up @@ -78,6 +77,17 @@ interface UpdateDebugProxyOptions {

export async function updateDebugProxy(s3: CloudStorage, storageUri: vscode.Uri, options?: UpdateDebugProxyOptions) {
logger.debug("updateDebugProxy", { storageUri: storageUri.fsPath, includePrerelease: options?.includePrerelease ?? false });

const pathConfig = getProxyPathConfig();
if (pathConfig !== undefined) {
const localVersion = await getLocalVersion(pathConfig);
if (localVersion) {
logger.info(`Configured Debug Proxy version v${localVersion}.`);
} else {
logger.error("Failed to get the version of configured Debug Proxy.");
}
return;
}

const remoteVersion = await getRemoteVersion(s3, options);
if (remoteVersion === undefined) {
Expand All @@ -86,7 +96,8 @@ export async function updateDebugProxy(s3: CloudStorage, storageUri: vscode.Uri,
}
logger.info(`Debug Proxy remote version v${remoteVersion}.`);

const localVersion = await getLocalVersion(storageUri);
const exeUri = exeFileName(storageUri);
const localVersion = await getLocalVersion(exeUri);
if (localVersion && semver.valid(localVersion) !== null) {
logger.info(`Debug Proxy local version v${localVersion}.`);
if (semver.satisfies(localVersion, `>=${remoteVersion}`, { includePrerelease: true })) {
Expand Down Expand Up @@ -133,7 +144,12 @@ export function shutdownDebugProxy() {

export async function launchDebugProxy(storageUri: vscode.Uri, options: DbosDebugConfig & { proxyPort?: number }) {

const exeUri = exeFileName(storageUri);
if (!getLaunchProxyConfig()) {
logger.info("debug proxy launch is disabled");
return;
}

const exeUri = getProxyPathConfig() ?? exeFileName(storageUri);
logger.debug("launchDebugProxy", { exeUri, launchOptions: options });
if (!(await exists(exeUri))) {
throw new Error("debug proxy doesn't exist", { cause: { path: exeUri.fsPath } });
Expand Down