Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | /* * This file is released under the MIT license. * Copyright (c) 2018, 2022, Mike Lischke * * See LICENSE file for more info. */ import { basename } from "path"; import { Uri, Webview, workspace } from "vscode"; import { WebviewProvider, IWebviewShowOptions } from "./WebviewProvider"; import { FrontendUtils } from "../FrontendUtils"; import { IDebuggerConsumer } from "../AntlrDebugAdapter"; import { GrammarDebugger } from "../../backend/GrammarDebugger"; export class ParseTreeProvider extends WebviewProvider implements IDebuggerConsumer { public debugger: GrammarDebugger; public debuggerStopped(uri: Uri): void { this.updateContent(uri); } public generateContent(webview: Webview, uri: Uri, _options: IWebviewShowOptions): string { const graph = this.debugger.currentParseTree; const rendererScriptPath = FrontendUtils.getOutPath("src/webview-scripts/ParseTreeRenderer.js", this.context, webview); const exportScriptPath = FrontendUtils.getOutPath("src/webview-scripts/GraphExport.js", this.context, webview); const graphLibPath = FrontendUtils.getNodeModulesPath(webview, "d3/dist/d3.js", this.context); const settings = workspace.getConfiguration("antlr4.debug"); const horizontal = settings.get<boolean>("visualParseTreeHorizontal", true); const clustered = settings.get<boolean>("visualParseTreeClustered", false); const nonce = this.generateNonce(); const diagram = `<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> ${this.generateContentSecurityPolicy(webview, nonce)} ${this.getStyles(webview)} <base target="_blank"> <script nonce="${nonce}" src="${graphLibPath}"></script> <script nonce="${nonce}"> let parseTreeRenderer; let graphExport; </script> </head> <body> <div class="header"><span class="parse-tree-color"><span class="graph-initial">Ⓟ</span>arse Tree</span> <span class="action-box"> Tree <span class="switch"> <span class="switch-border"> <input id="switch1" type="checkbox" onClick="parseTreeRenderer.toggleTreeType(this)"/> <label for="switch1"></label> <span class="switch-handle-top"></span> </span> </span> Cluster Horizontal <span class="switch"> <span class="switch-border"> <input id="switch2" type="checkbox" onClick="parseTreeRenderer.toggleOrientation(this)"/> <label for="switch2"></label> <span class="switch-handle-top"></span> </span> </span> Vertical <a onClick="parseTreeRenderer.changeNodeSize(0.9);"> <span class="parse-tree-color" style="font-size: 120%; font-weight: 800; cursor: pointer; vertical-align: middle;">-</span> </a> Node Size <a onClick="parseTreeRenderer.changeNodeSize(1.1);"> <span class="parse-tree-color" style="font-size: 120%; font-weight: 800; cursor: pointer; vertical-align: middle;">+</span> </a> Save to SVG <a onClick="graphExport.exportToSVG('parse-tree', '${basename(uri.fsPath)}');"> <span class="parse-tree-save-image" /> </a> </span> </div> <svg></svg> <script nonce="${nonce}" type="module"> import { ParseTreeRenderer } from "${rendererScriptPath}"; import { GraphExport } from "${exportScriptPath}"; // Register a listener for data changes. window.addEventListener("message", (event) => { switch (event.data.command) { case "updateParseTreeData": { parseTreeRenderer.loadNewTree({ parseTreeData: event.data.treeData }); break; } default: } }); parseTreeRenderer = new ParseTreeRenderer(); graphExport = new GraphExport(); parseTreeRenderer.loadNewTree({ parseTreeData: ${JSON.stringify(graph)}, useCluster: ${clustered.toString()}, horizontal: ${horizontal.toString()}, width: 1000, height: 1000, initialScale: 0.75, initialTranslateX: ${horizontal ? 200 : 500}, initialTranslateY: ${horizontal ? 400 : 50}, }); parseTreeRenderer.initSwitches(); </script> </body> </html>`; return diagram; } public updateContent(uri: Uri): boolean { const graph = this.debugger.currentParseTree; this.sendMessage(uri, { command: "updateParseTreeData", treeData: graph, }); return true; } } |