(filePath: string, fileName?: string, viewer?: vscode.ViewColumn, currentViewColumn?: vscode.ViewColumn)
| 309 | } |
| 310 | |
| 311 | private async previewDocument(filePath: string, fileName?: string, viewer?: vscode.ViewColumn, currentViewColumn?: vscode.ViewColumn): Promise<DisposableProcess | undefined> { |
| 312 | const knitWorkingDir = this.getKnitDir(knitDir, filePath); |
| 313 | const knitWorkingDirText = knitWorkingDir ? `${knitWorkingDir}` : ''; |
| 314 | this.rPath = await getRpath(); |
| 315 | |
| 316 | const lim = '<<<vsc>>>'; |
| 317 | const re = new RegExp(`.*${lim}(.*)${lim}.*`, 'ms'); |
| 318 | const outputFile = path.join(tmpDir(), crypto.createHash('sha256').update(filePath).digest('hex') + '.html'); |
| 319 | const scriptValues = { |
| 320 | 'VSCR_KNIT_DIR': knitWorkingDirText, |
| 321 | 'VSCR_LIM': lim, |
| 322 | 'VSCR_FILE_PATH': filePath.replace(/\\/g, '/'), |
| 323 | 'VSCR_OUTPUT_FILE': outputFile.replace(/\\/g, '/'), |
| 324 | 'VSCR_TMP_DIR': tmpDir().replace(/\\/g, '/') |
| 325 | }; |
| 326 | |
| 327 | |
| 328 | const callback = (dat: string, childProcess?: DisposableProcess) => { |
| 329 | const outputUrl = re.exec(dat)?.[0]?.replace(re, '$1'); |
| 330 | if (outputUrl) { |
| 331 | if (viewer !== undefined && fileName) { |
| 332 | const autoRefresh = config().get<boolean>('rmarkdown.preview.autoRefresh', false); |
| 333 | void this.openPreview( |
| 334 | vscode.Uri.file(outputUrl), |
| 335 | filePath, |
| 336 | fileName, |
| 337 | childProcess, |
| 338 | viewer, |
| 339 | currentViewColumn ?? vscode.ViewColumn.Active, |
| 340 | autoRefresh |
| 341 | ); |
| 342 | } |
| 343 | return true; |
| 344 | } |
| 345 | return false; |
| 346 | }; |
| 347 | |
| 348 | const onRejected = (filePath: string) => { |
| 349 | if (this.previewStore.has(filePath)) { |
| 350 | this.previewStore.delete(filePath); |
| 351 | } |
| 352 | }; |
| 353 | |
| 354 | if (knitWorkingDir && fileName) { |
| 355 | return await this.knitWithProgress( |
| 356 | { |
| 357 | workingDirectory: knitWorkingDir, |
| 358 | fileName: fileName, |
| 359 | filePath: filePath, |
| 360 | scriptPath: extensionContext.asAbsolutePath('R/rmarkdown/preview.R'), |
| 361 | scriptArgs: scriptValues, |
| 362 | rOutputFormat: 'html preview', |
| 363 | callback: callback, |
| 364 | onRejection: onRejected |
| 365 | } |
| 366 | ); |
| 367 | } |
| 368 | } |
no test coverage detected