Skip to content

Commit b003a0e

Browse files
authored
Fix console err (#1034)
* Check workspaceData in hover and completion * Update doWithProgress
1 parent 91e9c06 commit b003a0e

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

src/completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const roxygenTagCompletionItems = [
3131

3232
export class HoverProvider implements vscode.HoverProvider {
3333
provideHover(document: vscode.TextDocument, position: vscode.Position): vscode.Hover {
34-
if(!session.workspaceData.globalenv){
34+
if(!session.workspaceData?.globalenv){
3535
return null;
3636
}
3737

@@ -115,7 +115,7 @@ export class LiveCompletionItemProvider implements vscode.CompletionItemProvider
115115
completionContext: vscode.CompletionContext
116116
): vscode.CompletionItem[] {
117117
const items = [];
118-
if (token.isCancellationRequested) {
118+
if (token.isCancellationRequested || !session.workspaceData?.globalenv) {
119119
return items;
120120
}
121121

src/helpViewer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export class RHelp
423423
private async getAllAliases(): Promise<Alias[] | undefined> {
424424
const aliases = await doWithProgress(() =>
425425
this.aliasProvider.getAllAliases(),
426+
vscode.ProgressLocation.Window
426427
);
427428
if (!aliases) {
428429
void vscode.window.showErrorMessage(

src/helpViewer/packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class PackageManager {
178178

179179
// let the user pick and install a package from CRAN
180180
public async pickAndInstallPackages(pickMany: boolean = false): Promise<boolean> {
181-
const packages = await doWithProgress(() => this.getPackages(true));
181+
const packages = await doWithProgress(() => this.getPackages(true), this.rHelp.treeViewWrapper.viewId);
182182
if(!packages?.length){
183183
return false;
184184
}

src/helpViewer/treeView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type cmdName = keyof typeof nodeCommands;
4545
// necessary to implement Node.refresh(),
4646
// which is used to signal from a node that its contents/children have changed
4747
export class HelpTreeWrapper {
48+
public readonly viewId = 'rHelpPages';
4849
public rHelp: RHelp;
4950
public helpView: vscode.TreeView<Node>;
5051
public helpViewProvider: HelpViewProvider;
@@ -53,7 +54,7 @@ export class HelpTreeWrapper {
5354
this.rHelp = rHelp;
5455
this.helpViewProvider = new HelpViewProvider(this);
5556
this.helpView = vscode.window.createTreeView(
56-
'rHelpPages',
57+
this.viewId,
5758
{
5859
treeDataProvider: this.helpViewProvider,
5960
showCollapseAll: true
@@ -587,7 +588,7 @@ class RefreshNode extends MetaNode {
587588
iconPath = new vscode.ThemeIcon('refresh');
588589

589590
async callBack(){
590-
await doWithProgress(() => this.rHelp.refresh());
591+
await doWithProgress(() => this.rHelp.refresh(), this.wrapper.viewId);
591592
this.parent.pkgRootNode.refresh();
592593
}
593594
}

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export async function executeAsTask(name: string, cmdOrProcess: string, args?: s
261261
// executes a callback and shows a 'busy' progress bar during the execution
262262
// synchronous callbacks are converted to async to properly render the progress bar
263263
// default location is in the help pages tree view
264-
export async function doWithProgress<T>(cb: (token?: vscode.CancellationToken, progress?: vscode.Progress<T>) => T | Promise<T>, location: string | vscode.ProgressLocation = 'rHelpPages', title?: string, cancellable?: boolean): Promise<T> {
264+
export async function doWithProgress<T>(cb: (token?: vscode.CancellationToken, progress?: vscode.Progress<T>) => T | Promise<T>, location: (string | vscode.ProgressLocation) = vscode.ProgressLocation.Window, title?: string, cancellable?: boolean): Promise<T> {
265265
const location2 = (typeof location === 'string' ? { viewId: location } : location);
266266
const options: vscode.ProgressOptions = {
267267
location: location2,

0 commit comments

Comments
 (0)