Skip to content

Commit

Permalink
add settings for debug proxy path and launch to simplify debug proxy …
Browse files Browse the repository at this point in the history
…debugging (#40)
  • Loading branch information
devhawk authored Jul 22, 2024
1 parent 3985214 commit b8c6eea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
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

0 comments on commit b8c6eea

Please sign in to comment.