Skip to content

Commit

Permalink
Add isRendering to RMarkdownPreview (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
renkun-ken authored Oct 11, 2022
1 parent ff2f1bc commit 8af2cdc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rmarkdown/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RMarkdownPreview extends vscode.Disposable {
fileWatcher: fs.FSWatcher | undefined;
autoRefresh: boolean;
mtime: number;
isRendering: boolean;

constructor(title: string, cp: DisposableProcess | undefined, panel: vscode.WebviewPanel,
resourceViewColumn: vscode.ViewColumn, outputUri: vscode.Uri, filePath: string,
Expand All @@ -40,6 +41,7 @@ class RMarkdownPreview extends vscode.Disposable {
this.outputUri = outputUri;
this.autoRefresh = autoRefresh;
this.mtime = fs.statSync(filePath).mtime.getTime();
this.isRendering = false;
void this.refreshContent(useCodeTheme);
this.startFileWatcher(RMarkdownPreviewManager, filePath);
}
Expand All @@ -61,7 +63,7 @@ class RMarkdownPreview extends vscode.Disposable {
let fsTimeout: NodeJS.Timeout | null;
const fileWatcher = fs.watch(filePath, {}, () => {
const mtime = fs.statSync(filePath).mtime.getTime();
if (this.autoRefresh && !fsTimeout && mtime !== this.mtime) {
if (this.autoRefresh && !this.isRendering && !fsTimeout && mtime !== this.mtime) {
fsTimeout = setTimeout(() => { fsTimeout = null; }, 1000);
this.mtime = mtime;
void RMarkdownPreviewManager.updatePreview(this);
Expand Down Expand Up @@ -285,6 +287,7 @@ export class RMarkdownPreviewManager extends RMarkdownManager {
toUpdate?.cp?.dispose();

if (toUpdate && previewUri) {
toUpdate.isRendering = true;
const childProcess: DisposableProcess | void = await this.previewDocument(previewUri, toUpdate.title).catch(() => {
void vscode.window.showErrorMessage('There was an error in knitting the document. Please check the R Markdown output stream.');
this.rMarkdownOutput.show(true);
Expand All @@ -296,6 +299,7 @@ export class RMarkdownPreviewManager extends RMarkdownManager {
}

this.refreshPanel(toUpdate);
toUpdate.isRendering = false;
}

}
Expand Down

0 comments on commit 8af2cdc

Please sign in to comment.