Skip to content

Commit da6d778

Browse files
authored
Merge pull request #139 from tintinweb/138-visual-code-extension-unable-to-render
fixes #138
2 parents ef3b483 + e3d8fa8 commit da6d778

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## 0.3.4
4+
- fix: A bug could lead to the web view crashing when another extension created a DOT document (with automatically open enabled) and then executes the preview command - #138
5+
36
## 0.3.3
47
- update: API - Allow caller to define view options (preserveFocus, vieColumn) - #132
58
- fix: "openAutomatically" creates a new URI object. When revealing the graph for an already rendered `.dot` file the extension would open another render view because the lookup if the panel already exists fails as `vscode.URI` objects are not singletons (`new vscode.Uri("hi") != new vscode.Uri("hi")`. in order to fix this we now index `vscode.Uri.toString()` in the `URI -> panelObject` mapping. - #131 #132

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "graphviz-interactive-preview",
33
"displayName": "Graphviz Interactive Preview",
44
"description": "Graphviz (dot) Interactive Preview",
5-
"version": "0.3.3",
5+
"version": "0.3.4",
66
"keywords": [
77
"dot",
88
"graphviz",

src/features/previewPanel.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export default class PreviewPanel {
4040

4141
renderLockTimeout: number;
4242

43+
private initialized: boolean;
44+
4345
// eslint-disable-next-line no-unused-vars
4446
progressResolve?: (value?:unknown) => void;
4547

@@ -81,28 +83,30 @@ export default class PreviewPanel {
8183
this.renderLockTimeout = (this.enableRenderLock && renderLockAdditionalTimeout >= 0)
8284
? renderLockAdditionalTimeout + viewTransitionDelay + viewTransitionaDuration
8385
: 0;
86+
87+
this.initialized = false;
8488
}
8589

86-
reveal(displayColumn: vscode.ViewColumn, preserveFocus?: boolean) {
90+
public reveal(displayColumn: vscode.ViewColumn, preserveFocus?: boolean) {
8791
this.panel.reveal(displayColumn, preserveFocus);
8892
}
8993

90-
setNeedsRebuild(needsRebuild : boolean) {
94+
public setNeedsRebuild(needsRebuild : boolean) {
9195
this.needsRebuild = needsRebuild;
9296
}
9397

94-
getNeedsRebuild() {
98+
public getNeedsRebuild() {
9599
return this.needsRebuild;
96100
}
97101

98-
getPanel() {
102+
public getPanel() {
99103
return this.panel;
100104
}
101105

102106
// the following functions do not use any locking/synchronization mechanisms,
103107
// so it may behave weirdly in edge cases
104108

105-
requestRender(dotSrc: string) {
109+
public requestRender(dotSrc: string) {
106110
const now = Date.now();
107111
const sinceLastRequest = now - this.lastRequest;
108112
const sinceLastRender = now - this.lastRender;
@@ -111,6 +115,8 @@ export default class PreviewPanel {
111115
// save the latest content
112116
this.waitingForRendering = dotSrc;
113117

118+
if (!this.initialized) return;
119+
114120
// hardcoded:
115121
// why: to filter out double-events on-save on-change etc, while preserving
116122
// the ability to monitor fast-changing files etc.
@@ -153,7 +159,7 @@ export default class PreviewPanel {
153159
}
154160

155161
// Renders content which has been put in the waiting quue
156-
renderWaitingContent() {
162+
private renderWaitingContent() {
157163
// clear the timeout and null it's handle, we are rendering any waiting content now!
158164
if (this.timeoutForWaiting) {
159165
console.log("renderWaitingContent() clearing existing timeout");
@@ -179,7 +185,7 @@ export default class PreviewPanel {
179185
* Sends the DOT source to the rendering panel
180186
* @param dotSrc DOT source
181187
*/
182-
renderNow(dotSrc : string) {
188+
private renderNow(dotSrc : string) {
183189
console.log("renderNow()");
184190
this.lockRender = true;
185191
this.lastRender = Date.now();
@@ -216,7 +222,7 @@ export default class PreviewPanel {
216222
}
217223

218224
// eslint-disable-next-line class-methods-use-this
219-
handleMessage(message: {
225+
public handleMessage(message: {
220226
command: any; value?: {
221227
err: any; // save the latest content
222228
// save the latest content
@@ -245,7 +251,7 @@ export default class PreviewPanel {
245251
* Restarts the renderWaiting function after the render lock has
246252
* timed out.
247253
*/
248-
restartRender() {
254+
private restartRender() {
249255
if (this.timeoutForRendering) {
250256
clearTimeout(this.timeoutForRendering);
251257
this.timeoutForRendering = undefined;
@@ -259,7 +265,7 @@ export default class PreviewPanel {
259265
* @param err
260266
*/
261267
// eslint-disable-next-line no-undef
262-
onRenderFinished(err?: string) {
268+
public onRenderFinished(err?: string) {
263269
diagnosticCollection.clear();
264270
if (err) {
265271
console.log(`rendering failed: ${err}`);
@@ -297,7 +303,8 @@ export default class PreviewPanel {
297303
/**
298304
* Called by the Webview after it has been loaded.
299305
*/
300-
onPageLoaded() {
306+
public onPageLoaded() {
307+
this.initialized = true;
301308
this.panel.webview.postMessage({
302309
command: "setConfig",
303310
value: {
@@ -313,7 +320,7 @@ export default class PreviewPanel {
313320
* Function which is called after disposing of the PreviewPanel
314321
* (typically after closing the tab)
315322
*/
316-
dispose() {
323+
public dispose() {
317324
// Resolve all remaining promises on disposal
318325
if (this.progressResolve) {
319326
this.progressResolve();

0 commit comments

Comments
 (0)