(viewer: vscode.ViewColumn, uri?: vscode.Uri)
| 196 | |
| 197 | |
| 198 | public async previewRmd(viewer: vscode.ViewColumn, uri?: vscode.Uri): Promise<void> { |
| 199 | const textEditor = vscode.window.activeTextEditor; |
| 200 | if (!textEditor) { |
| 201 | void vscode.window.showErrorMessage('No text editor active.'); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | const filePath = uri ? uri.fsPath : textEditor.document.uri.fsPath; |
| 206 | const fileName = path.basename(filePath); |
| 207 | const currentViewColumn: vscode.ViewColumn = vscode.window.activeTextEditor?.viewColumn ?? vscode.ViewColumn.Active ?? vscode.ViewColumn.One; |
| 208 | |
| 209 | // handle untitled rmd files |
| 210 | if (!uri && textEditor.document.isUntitled) { |
| 211 | void vscode.window.showWarningMessage('Cannot knit an untitled file. Please save the document.'); |
| 212 | await vscode.commands.executeCommand('workbench.action.files.save').then(() => { |
| 213 | if (!textEditor.document.isUntitled) { |
| 214 | void this.previewRmd(viewer); |
| 215 | } |
| 216 | }); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | const isSaved = uri ? |
| 221 | true : |
| 222 | await saveDocument(textEditor.document); |
| 223 | |
| 224 | if (!isSaved) { |
| 225 | return; |
| 226 | } |
| 227 | // don't knit if the current uri is already being knit |
| 228 | if (this.busyUriStore.has(filePath)) { |
| 229 | return; |
| 230 | } else if (this.previewStore.has(filePath)) { |
| 231 | this.previewStore.get(filePath)?.panel.reveal(); |
| 232 | } else { |
| 233 | this.busyUriStore.add(filePath); |
| 234 | await this.previewDocument(filePath, fileName, viewer, currentViewColumn); |
| 235 | this.busyUriStore.delete(filePath); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | public enableAutoRefresh(preview?: RMarkdownPreview): void { |
| 240 | if (preview) { |
no test coverage detected