Skip to content

Commit

Permalink
Fixed bug that can not be previewed for multiple plantuml codes in th…
Browse files Browse the repository at this point in the history
…e same file.
  • Loading branch information
jhuix committed Sep 15, 2020
1 parent 83d2e0b commit a6d1767
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"@types/mkdirp": "^1.0.1",
"@types/node": "^12.12.58",
"@types/vscode": "^1.47.0",
"eslint": "^7.9.0",
"glob": "^7.1.4",
"semver": "^7.3.2",
"tslint": "^6.1.3",
Expand Down
15 changes: 10 additions & 5 deletions src/plantuml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as child_process from 'child_process';
import * as path from 'path';

const { debounce } = require('throttle-debounce');
const extensionDirectoryPath = path.resolve(__dirname, '../');
const PlantumlJarPath = path.resolve(extensionDirectoryPath, 'media/plantuml/plantuml.jar');

Expand All @@ -32,12 +33,15 @@ class PlantumlRenderer {
private resolves: Array<(result: string) => void>;
private closeResolves: Array<(result: string) => void>;
private render: child_process.ChildProcessWithoutNullStreams | null;
private endRender = debounce(1000, (render: child_process.ChildProcessWithoutNullStreams) => {
render.stdin.end();
});

public constructor(fileDirectoryPath: string) {
this.fileDirectoryPath = fileDirectoryPath;
this.chunks = CHUNKS[this.fileDirectoryPath] || '';
this.resolves = RESOLVES[this.fileDirectoryPath] || [];
this.closeResolves = CLOSE_RESOLVES[this.fileDirectoryPath] || [];
this.chunks = CHUNKS[fileDirectoryPath] || '';
this.resolves = RESOLVES[fileDirectoryPath] || [];
this.closeResolves = CLOSE_RESOLVES[fileDirectoryPath] || [];
this.render = null;
this.startRender();
}
Expand All @@ -46,8 +50,8 @@ class PlantumlRenderer {
return new Promise((resolve, reject) => {
if (this.render) {
this.resolves.push(resolve);
this.render.stdin.write(content);
this.render.stdin.end();
this.render.stdin.write(content + '\n');
this.endRender(this.render);
} else {
reject('Task is not exist.');
}
Expand Down Expand Up @@ -116,6 +120,7 @@ class PlantumlRenderer {
callback('true');
}
CLOSE_RESOLVES[this.fileDirectoryPath] = this.closeResolves;
this.render = null;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ export class ShowdownPreviewer {
* Close preview
*/
public dispose() {
plantumlAPI.closeRender(path.resolve(__dirname, '../media/plantuml'));
let dir = path.resolve(__dirname, '../media/plantuml');
if (this.uri) {
dir += path.delimiter + path.dirname(this.uri.fsPath);
}
plantumlAPI.closeRender(dir);
if (this.webpanel) {
this.webpanel.dispose();
}
Expand Down

0 comments on commit a6d1767

Please sign in to comment.