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 11, 2023
1 parent ed43a6f commit 8857562
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions vscode-trace-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {
}
}));

const updateUris = async (): Promise<void> => {
const baseUri = vscode.Uri.parse(getTraceServerUrl());
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();
await updateUris();
if (await isUp()) {
fileOpenHandler(context, file);
}
Expand All @@ -67,14 +78,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 @@ -115,6 +119,7 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {

context.subscriptions.push(vscode.commands.registerCommand('openedTraces.openTraceFolder', async () => {
await startTraceServerIfAvailable();
await updateUris();
if (await isUp()) {
fileOpenHandler(context, undefined);
}
Expand All @@ -126,6 +131,7 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI {

context.subscriptions.push(vscode.commands.registerCommand('serverStatus.started', () => {
serverStatusService.render(true);
updateUris();
if (tracesProvider) {
tracesProvider.postMessagetoWebview(VSCODE_MESSAGES.TRACE_SERVER_STARTED, undefined);
}
Expand Down

0 comments on commit 8857562

Please sign in to comment.