fix embedded workbench

This commit is contained in:
Simon Knott 2024-11-04 14:53:41 +01:00
parent 69ba2d1d66
commit 9d595de806
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 11 additions and 2 deletions

View file

@ -21,6 +21,7 @@ import './embeddedWorkbenchLoader.css';
import { Workbench } from './workbench';
import { currentTheme, toggleTheme } from '@web/theme';
import type { SourceLocation } from './modelUtil';
import { filePathToTraceURL } from './uiModeTraceView';
function openPage(url: string, target?: string) {
if (url)
@ -40,7 +41,15 @@ export const EmbeddedWorkbenchLoader: React.FunctionComponent = () => {
React.useEffect(() => {
window.addEventListener('message', async ({ data: { method, params } }) => {
if (method === 'loadTraceRequested') {
setTraceURLs(params.traceUrl ? [params.traceUrl] : []);
if (params.traceUrl) {
// the param is called URL, but VS Code sends a path
const url = params.traceUrl.startsWith('http')
? params.traceUrl
: filePathToTraceURL(params.traceUrl).toString();
setTraceURLs([url]);
} else {
setTraceURLs([]);
}
setProcessingErrorMessage(null);
} else if (method === 'applyTheme') {
if (currentTheme() !== params.theme)

View file

@ -125,7 +125,7 @@ function formatUrl(traceURL: URL) {
return traceURL;
}
function filePathToTraceURL(path: string) {
export function filePathToTraceURL(path: string) {
const url = new URL('file', location.href);
url.searchParams.set('path', path);
return url;