Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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