Skip to content

Commit

Permalink
Use asExternalUri For Server Url
Browse files Browse the repository at this point in the history
This allows for automatic port forwarding of trace-server api calls when using remote.

Signed-off-by: Will Yang <[email protected]>
  • Loading branch information
williamsyang-work committed Aug 9, 2023
1 parent ed43a6f commit 351d3dc
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions vscode-trace-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
}
}));

const updateUris = async (url?: string): Promise<void> => {
url = url ?? getTraceServerUrl();
const baseUri = vscode.Uri.parse(url);
const extUri = await vscode.env.asExternalUri(baseUri);
const extUriString = extUri.toString();

tracesProvider.updateTraceServerUrl(extUriString);
myAnalysisProvider.updateTraceServerUrl(extUriString);
TraceViewerPanel.updateTraceServerUrl(extUriString);
};

const analysisProvider = new AnalysisProvider();
// TODO: For now, a different command opens traces from file explorer. Remove when we have a proper trace finder
const fileOpenHandler = fileHandler(analysisProvider);
context.subscriptions.push(vscode.commands.registerCommand('traces.openTraceFile', async file => {
await startTraceServerIfAvailable();
const url = await startTraceServerIfAvailable();
await updateUris(url);
if (await isUp()) {
fileOpenHandler(context, file);
}
Expand All @@ -67,14 +79,7 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
}

if (e.affectsConfiguration('trace-compass.traceserver.url')) {
const newUrl = getTraceServerUrl();

// Signal the change to the `Opened traces` and `Available views` webview
tracesProvider.updateTraceServerUrl(newUrl);
myAnalysisProvider.updateTraceServerUrl(newUrl);

// Signal the change to all trace panels
TraceViewerPanel.updateTraceServerUrl(newUrl);
updateUris();
}
}));

Expand Down Expand Up @@ -114,7 +119,8 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
}));

context.subscriptions.push(vscode.commands.registerCommand('openedTraces.openTraceFolder', async () => {
await startTraceServerIfAvailable();
const url = await startTraceServerIfAvailable();
await updateUris(url);
if (await isUp()) {
fileOpenHandler(context, undefined);
}
Expand Down Expand Up @@ -145,13 +151,13 @@ export function deactivate(): void {
traceExtensionWebviewManager.dispose();
}

async function startTraceServerIfAvailable(): Promise<void> {
async function startTraceServerIfAvailable(): Promise<string | undefined> {
const extensionId = 'vscode-trace-server';
const traceServerExtension = vscode.extensions.getExtension('tracecompass-community.' + extensionId);
if (!traceServerExtension || await isUp()) {
return;
}
await vscode.commands.executeCommand(extensionId + '.start-if-stopped');
return vscode.commands.executeCommand(extensionId + '.start-if-stopped');
}

async function isUp() {
Expand Down

0 comments on commit 351d3dc

Please sign in to comment.