Skip to content

Commit

Permalink
Merge pull request #139 from tintinweb/138-visual-code-extension-unab…
Browse files Browse the repository at this point in the history
…le-to-render

fixes #138
  • Loading branch information
tintinweb authored Oct 15, 2022
2 parents ef3b483 + e3d8fa8 commit da6d778
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 0.3.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

## 0.3.3
- update: API - Allow caller to define view options (preserveFocus, vieColumn) - #132
- 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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "graphviz-interactive-preview",
"displayName": "Graphviz Interactive Preview",
"description": "Graphviz (dot) Interactive Preview",
"version": "0.3.3",
"version": "0.3.4",
"keywords": [
"dot",
"graphviz",
Expand Down
31 changes: 19 additions & 12 deletions src/features/previewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default class PreviewPanel {

renderLockTimeout: number;

private initialized: boolean;

// eslint-disable-next-line no-unused-vars
progressResolve?: (value?:unknown) => void;

Expand Down Expand Up @@ -81,28 +83,30 @@ export default class PreviewPanel {
this.renderLockTimeout = (this.enableRenderLock && renderLockAdditionalTimeout >= 0)
? renderLockAdditionalTimeout + viewTransitionDelay + viewTransitionaDuration
: 0;

this.initialized = false;
}

reveal(displayColumn: vscode.ViewColumn, preserveFocus?: boolean) {
public reveal(displayColumn: vscode.ViewColumn, preserveFocus?: boolean) {
this.panel.reveal(displayColumn, preserveFocus);
}

setNeedsRebuild(needsRebuild : boolean) {
public setNeedsRebuild(needsRebuild : boolean) {
this.needsRebuild = needsRebuild;
}

getNeedsRebuild() {
public getNeedsRebuild() {
return this.needsRebuild;
}

getPanel() {
public getPanel() {
return this.panel;
}

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

requestRender(dotSrc: string) {
public requestRender(dotSrc: string) {
const now = Date.now();
const sinceLastRequest = now - this.lastRequest;
const sinceLastRender = now - this.lastRender;
Expand All @@ -111,6 +115,8 @@ export default class PreviewPanel {
// save the latest content
this.waitingForRendering = dotSrc;

if (!this.initialized) return;

// hardcoded:
// why: to filter out double-events on-save on-change etc, while preserving
// the ability to monitor fast-changing files etc.
Expand Down Expand Up @@ -153,7 +159,7 @@ export default class PreviewPanel {
}

// Renders content which has been put in the waiting quue
renderWaitingContent() {
private renderWaitingContent() {
// clear the timeout and null it's handle, we are rendering any waiting content now!
if (this.timeoutForWaiting) {
console.log("renderWaitingContent() clearing existing timeout");
Expand All @@ -179,7 +185,7 @@ export default class PreviewPanel {
* Sends the DOT source to the rendering panel
* @param dotSrc DOT source
*/
renderNow(dotSrc : string) {
private renderNow(dotSrc : string) {
console.log("renderNow()");
this.lockRender = true;
this.lastRender = Date.now();
Expand Down Expand Up @@ -216,7 +222,7 @@ export default class PreviewPanel {
}

// eslint-disable-next-line class-methods-use-this
handleMessage(message: {
public handleMessage(message: {
command: any; value?: {
err: any; // save the latest content
// save the latest content
Expand Down Expand Up @@ -245,7 +251,7 @@ export default class PreviewPanel {
* Restarts the renderWaiting function after the render lock has
* timed out.
*/
restartRender() {
private restartRender() {
if (this.timeoutForRendering) {
clearTimeout(this.timeoutForRendering);
this.timeoutForRendering = undefined;
Expand All @@ -259,7 +265,7 @@ export default class PreviewPanel {
* @param err
*/
// eslint-disable-next-line no-undef
onRenderFinished(err?: string) {
public onRenderFinished(err?: string) {
diagnosticCollection.clear();
if (err) {
console.log(`rendering failed: ${err}`);
Expand Down Expand Up @@ -297,7 +303,8 @@ export default class PreviewPanel {
/**
* Called by the Webview after it has been loaded.
*/
onPageLoaded() {
public onPageLoaded() {
this.initialized = true;
this.panel.webview.postMessage({
command: "setConfig",
value: {
Expand All @@ -313,7 +320,7 @@ export default class PreviewPanel {
* Function which is called after disposing of the PreviewPanel
* (typically after closing the tab)
*/
dispose() {
public dispose() {
// Resolve all remaining promises on disposal
if (this.progressResolve) {
this.progressResolve();
Expand Down

0 comments on commit da6d778

Please sign in to comment.