Skip to content

Commit

Permalink
Fix railroad webview serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jun 15, 2023
1 parent 24f2f43 commit bfc86fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/langium-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
}
},
"activationEvents": [
"onLanguage:langium"
"onLanguage:langium",
"onWebviewPanel:railroadDiagram"
],
"vsce": {
"dependencies": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export function registerRailroadConnectionHandler(connection: Connection, servic
return undefined;
}
const generatedRailroadHtml = createGrammarDiagramHtml(document.parseResult.value as Grammar, {
javascript: `const vscode = acquireVsCodeApi(); vscode.setState(${JSON.stringify(uri)});`
// Setting the state to the current uri allows us to open the webview on vscode restart
javascript: `
const vscode = acquireVsCodeApi();
vscode.setState(${JSON.stringify(uri)});
`
});
return generatedRailroadHtml;
} catch {
Expand Down
6 changes: 6 additions & 0 deletions packages/langium-vscode/src/railroad-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class RailroadDiagramSerializer implements vscode.WebviewPanelSerializer {
if (typeof state === 'string') {
const uri = vscode.Uri.parse(state);
RailroadDiagramPanel.revive(webviewPanel, this.client, uri);
} else {
// Invalid state, just close the webview
webviewPanel.dispose();
}
return Promise.resolve();
}
Expand Down Expand Up @@ -75,6 +78,9 @@ export class RailroadDiagramPanel implements vscode.Disposable {
this.uri = uri.toString();
this.client = client;
this.panel = panel;
this.panel.webview.options = {
enableScripts: true
};
vscode.window.onDidChangeActiveTextEditor(e => {
if (e?.document.uri.path.endsWith('.langium')) {
this.update(e.document.uri.toString());
Expand Down

0 comments on commit bfc86fb

Please sign in to comment.