Skip to content

Commit

Permalink
Make help preview async (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHentschel committed Dec 8, 2022
1 parent d0389f9 commit 8d7d9ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/helpViewer/helpPreviewer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import * as cp from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as rHelp from './index';
import * as ejs from 'ejs';
import { isDirSafe, isFileSafe, readFileSyncSafe, config } from '../util';
import { isDirSafe, isFileSafe, readFileSyncSafe, config, spawnAsync } from '../util';
import { Topic, TopicType } from './packages';


Expand Down Expand Up @@ -210,7 +209,7 @@ export class RLocalHelpPreviewer {
}

// Methods that imitate the HelpProvider
public getHelpFileFromRequestPath(requestPath: string): undefined | rHelp.HelpFile {
public async getHelpFileFromRequestPath(requestPath: string): Promise<undefined | rHelp.HelpFile> {
if(this.isDisposed){
return undefined;
}
Expand All @@ -224,10 +223,10 @@ export class RLocalHelpPreviewer {
if(topic === 'DESCRIPTION'){
return this.getHelpForDescription(requestPath);
}
return this.getHelpForTopic(topic, requestPath);
return await this.getHelpForTopic(topic, requestPath);
}

private getHelpForTopic(topic: string, requestPath: string): undefined | rHelp.HelpFile {
private async getHelpForTopic(topic: string, requestPath: string): Promise<undefined | rHelp.HelpFile> {
// Make sure the topic has a valid .Rd file
const rdFileName = this.getRdPathForTopic(topic);
if(!rdFileName || !isFileSafe(rdFileName)){
Expand All @@ -248,7 +247,7 @@ export class RLocalHelpPreviewer {
this.getPackageInfo()?.version || DUMMY_TOPIC_VERSION,
this.packageDir
];
const spawnRet = cp.spawnSync(this.rPath, args, {encoding: 'utf-8'});
const spawnRet = await spawnAsync(this.rPath, args);
if(spawnRet.status){
// The user expects this to work, so we show a warning if it doesn't:
const msg = `Failed to convert .Rd file ${rdFileName} (status: ${spawnRet.status}): ${spawnRet.stderr}`;
Expand Down
6 changes: 3 additions & 3 deletions src/helpViewer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export class RHelp implements api.HelpPanel, vscode.WebviewPanelSerializer<strin
skipCache: boolean = false
): Promise<HelpFile | undefined> {
// try to get a preview first
const preview = this.getHelpPreviewForPath(requestPath);
const preview = await this.getHelpPreviewForPath(requestPath);
if(preview){
pimpMyHelp(preview);
return preview;
Expand Down Expand Up @@ -639,9 +639,9 @@ export class RHelp implements api.HelpPanel, vscode.WebviewPanelSerializer<strin
return helpFile;
}

private getHelpPreviewForPath(requestPath: string): HelpFile | undefined {
private async getHelpPreviewForPath(requestPath: string): Promise<HelpFile | undefined> {
for (const previewer of this.previewProviders) {
const ret = previewer.getHelpFileFromRequestPath(requestPath);
const ret = await previewer.getHelpFileFromRequestPath(requestPath);
if(ret){
return ret;
}
Expand Down

0 comments on commit 8d7d9ae

Please sign in to comment.