-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathtreeView.ts
More file actions
717 lines (615 loc) · 25 KB
/
Copy pathtreeView.ts
File metadata and controls
717 lines (615 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import * as vscode from 'vscode';
import { RHelp } from '.';
import { extensionContext } from '../extension';
import { doWithProgress } from '../util';
import { RLocalHelpPreviewer } from './helpPreviewer';
import { Package, Topic, TopicType } from './packages';
// this enum is re-assigned just for code readability
const CollapsibleState = vscode.TreeItemCollapsibleState;
// the commands contributed in package.json for the tree view
// the commands are registered in HelpTreeWrapper.constructor
// the node-objects only need to handle the keys ('QUICKPICK' etc.) in Node.handleCommand()
const nodeCommands = {
QUICKPICK: 'r.helpPanel.showQuickPick', // called to show the children of a node in a quickpick
CALLBACK: 'r.helpPanel.internalCallback', // called when the item is clicked and node.command is not null
searchPackage: 'r.helpPanel.searchPackage',
openInNewPanel: 'r.helpPanel.openInNewPanel',
clearCache: 'r.helpPanel.clearCache',
removeFromFavorites: 'r.helpPanel.removeFromFavorites',
addToFavorites: 'r.helpPanel.addToFavorites',
removePackage: 'r.helpPanel.removePackage',
updatePackage: 'r.helpPanel.updatePackage',
showOnlyFavorites: 'r.helpPanel.showOnlyFavorites',
showAllPackages: 'r.helpPanel.showAllPackages',
filterPackages: 'r.helpPanel.filterPackages',
summarizeTopics: 'r.helpPanel.summarizeTopics',
unsummarizeTopics: 'r.helpPanel.unsummarizeTopics',
installPackages: 'r.helpPanel.installPackages',
updateInstalledPackages: 'r.helpPanel.updateInstalledPackages'
} as const;
// used to avoid typos when handling commands
type cmdName = keyof typeof nodeCommands;
////////////////////
// The following classes are mostly just an 'adapter layer' between vscode's treeview interface
// and the object oriented approach used here to present nodes of the treeview.
// The 'interesting' part of the nodes is implemented below
// wrapper around vscode.window.createTreeView()
// necessary to implement Node.refresh(),
// which is used to signal from a node that its contents/children have changed
export class HelpTreeWrapper {
public readonly viewId = 'rHelpPages';
public rHelp: RHelp;
public helpView: vscode.TreeView<Node>;
public helpViewProvider: HelpViewProvider;
constructor(rHelp: RHelp){
this.rHelp = rHelp;
this.helpViewProvider = new HelpViewProvider(this);
this.helpView = vscode.window.createTreeView(
this.viewId,
{
treeDataProvider: this.helpViewProvider,
showCollapseAll: true
}
);
// register the commands defined in `nodeCommands`
// they still need to be defined in package.json (apart from CALLBACK)
for (const cmd in nodeCommands) {
const cmdTyped = cmd as cmdName; // Ok since `cmdName` is defiend as `keyof typeof nodeCommands`
extensionContext.subscriptions.push(vscode.commands.registerCommand(nodeCommands[cmdTyped], (node: Node | undefined) => {
// treeview-root is represented by `undefined`:
node ||= this.helpViewProvider.rootItem;
node.handleCommand(cmdTyped);
}));
}
}
public refreshNode(node: Node | undefined): void {
for(const listener of this.helpViewProvider.listeners){
listener(node);
}
}
public refreshPackageRootNode(): void {
this.helpViewProvider.rootItem?.pkgRootNode?.refresh();
}
public refreshPreviewNode(packageDir: string): void {
this.helpViewProvider.rootItem.previewChildren?.forEach(node => {
if(node.packageDir === packageDir){
node.refresh(true);
}
});
}
public refreshRootNode(): void {
this.helpViewProvider.rootItem.refresh(true);
}
}
// mostly just a wrapper to implement vscode.TreeDataProvider
export class HelpViewProvider implements vscode.TreeDataProvider<Node> {
public rootItem: RootNode;
public listeners: ((e: Node | undefined) => void)[] = [];
constructor(wrapper: HelpTreeWrapper){
this.rootItem = new RootNode(wrapper);
}
onDidChangeTreeData(listener: (e: Node | undefined) => void): vscode.Disposable {
this.listeners.push(listener);
return new vscode.Disposable(() => {
// do nothing
});
}
getChildren(element?: Node): vscode.ProviderResult<Node[]>{
element ||= this.rootItem;
return element.getChildren();
}
getTreeItem(element: Node): Node {
return element;
}
getParent(element: Node): Node | undefined {
return element.parent;
}
}
// Abstract base class for nodes of the treeview
// Is a rather technical base class to handle the intricacies of vscode's treeview API
// All the 'interesting' stuff hapens in the derived classes
// New commands should (if possible) be implemented by defining a new derived class,
// rather than modifying this class!
abstract class Node extends vscode.TreeItem{
// TreeItem (defaults for this usecase)
declare public description?: string;
public collapsibleState: vscode.TreeItemCollapsibleState = vscode.TreeItemCollapsibleState.None;
public contextValue: string = '';
declare public label?: string;
declare public tooltip?: string;
// set to null/undefined in derived class to expand/collapse on click
public command = {
title: 'treeNodeCallback', // is this title used anywhere?
command: nodeCommands.CALLBACK,
arguments: [this]
} as vscode.Command | undefined;
// Node
public parent: Node | undefined = undefined;
public children?: Node[] = undefined;
// These can be used to modify the behaviour of a node when showed as/in a quickpick:
public quickPickCommand?: cmdName; // defaults to this.showQuickPick or callBack
public qpLabel?: string; // defaults to node.icon + node.label
public qpDetail?: string; // defaults to node.detail || node.description || node.toolTip
public qpPrompt?: string; // defaults to empty input bar
// These are shared between nodes to access functions of the help panel etc.
// could also be static?
readonly wrapper: HelpTreeWrapper;
readonly rootNode?: RootNode;
// used to give unique ids to nodes
static newId: number = 0;
// The default constructor just copies some info from parent
constructor(parent: Node | undefined, wrapper: HelpTreeWrapper){
super('');
this.wrapper = wrapper;
if(parent){
this.parent = parent;
this.rootNode = parent.rootNode;
}
this.id = `${Node.newId++}`;
}
// Called when a node or command-button on a node is clicked
// Only internal commands are handled here, custom commands are implemented in _handleCommand!
public handleCommand(cmd: cmdName){
if(cmd === 'CALLBACK' && this.callBack){
void this.callBack();
} else if(cmd === 'QUICKPICK'){
if(this.quickPickCommand){
this._handleCommand(this.quickPickCommand);
} else if(this.collapsibleState !== CollapsibleState.None){
void this.showQuickPick();
} else{
this.handleCommand('CALLBACK');
}
} else {
this._handleCommand(cmd);
}
}
// overwrite this in derived classes to handle custom commands
protected _handleCommand(cmd: cmdName): void;
protected _handleCommand(){
// to be overwritten
}
// implement this to handle callBacks (simple clicks on a node)
// can also be implemented in _handleCommand('CALLBACK')
public callBack?(): void | Promise<void>;
// Shows a quickpick containing the children of a node
// If the picked child has children itself, another quickpick is shown
// Otherwise, its QUICKPICK or CALLBACK command is executed
public async showQuickPick(){
const children = await this.makeChildren(true);
if(!children){
return undefined;
}
const qpItems: (vscode.QuickPickItem & {child: Node})[] = children.map(v => {
let label = v.label || '';
if(typeof v.iconPath === 'object' && 'id' in v.iconPath){
label = `$(${v.iconPath.id}) ${label}`;
}
return {
label: v.qpLabel ?? label,
detail: v.qpDetail ?? v.description ?? v.tooltip,
child: v
};
});
const qp = await vscode.window.showQuickPick(qpItems, {
placeHolder: this.qpPrompt
});
if(qp){
const child = qp.child;
child.handleCommand('QUICKPICK');
}
}
// Called by vscode etc. to get the children of a node
// Not meant to be modified in derived classes!
public async getChildren(): Promise<Node[]|undefined> {
if(this.children === undefined){
this.children = await this.makeChildren();
}
return this.children;
}
// to be overwritten, if the node has any children
protected makeChildren(forQuickPick?: boolean): Promise<Node[]|undefined> | Node[] | undefined;
protected makeChildren(): Promise<Node[]|undefined> | Node[] | undefined {
return [];
}
// Can be called by a method from the node itself or externally to refresh the node in the treeview
public refresh(refreshChildren: boolean = true){
if(refreshChildren){
this.children = undefined;
}
this.wrapper.refreshNode(this);
}
// Clear 'grandchildren' without triggering the treeview to update too often
public refreshChildren(){
if(this.children){
for(const child of this.children){
child.children = undefined;
}
}
}
// show/focus the node in the treeview
public reveal(options?: { select?: boolean, focus?: boolean, expand?: boolean | number }){
void this.wrapper.helpView.reveal(this, options);
}
// These methods are used to update this.contextValue with possible command names
// The constructed contextValue contains the command names of the commands applying to this node
static makeContextValue(...args: cmdName[]){
return args.map(v => `_${v}_`).join('');
}
public addContextValues(...args: cmdName[]){
args.forEach(val => {
this.contextValue += `_${val}_`;
});
return this.contextValue;
}
public removeContextValues(...args: cmdName[]){
args.forEach(val => {
this.contextValue = this.contextValue.replace(new RegExp(`_${val}_`), '');
});
return this.contextValue;
}
public replaceContextValue(oldCmd: cmdName, newCmd: cmdName){
this.removeContextValues(oldCmd);
return this.addContextValues(newCmd);
}
}
abstract class NonRootNode extends Node {
parent: RootNode | NonRootNode;
rootNode: RootNode;
public constructor(parent: RootNode | NonRootNode){
super(parent, parent.wrapper);
this.parent = parent;
this.rootNode = parent.rootNode;
}
}
///////////////////////////////////
// The following classes contain the implementation of the help-view-specific behaviour
// PkgRootNode, PackageNode, and TopicNode are a bit more complex
// The remaining nodes mostly just contain an icon and a callback
// Root of the node. Is not actually used by vscode, but as 'imaginary' root item.
class RootNode extends Node {
public collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
public label = 'root';
readonly rootNode = this;
public pkgRootNode?: PkgRootNode;
public staticChildren?: NonRootNode[];
public previewChildren?: PreviewPackageNode[];
constructor(wrapper: HelpTreeWrapper){
super(undefined, wrapper);
}
makeChildren(){
this.pkgRootNode ||= new PkgRootNode(this);
this.staticChildren ||= [
new HomeNode(this),
new Search1Node(this),
new Search2Node(this),
new OpenForSelectionNode(this),
new RefreshNode(this),
new InstallPackageNode(this),
this.pkgRootNode,
];
this.previewChildren ||= this.wrapper.rHelp.previewProviders.map(
previewer => new PreviewPackageNode(this, previewer)
);
return [...this.staticChildren, ...this.previewChildren];
}
public refresh(refreshChildren: boolean = true){
if(refreshChildren){
this.children = undefined;
this.previewChildren = undefined;
}
this.wrapper.refreshNode(undefined);
}
}
// contains the list of installed packages
class PkgRootNode extends NonRootNode {
// TreeItem
public label = 'Help Topics by Package';
public iconPath = new vscode.ThemeIcon('list-unordered');
public description = '';
public command = undefined;
public collapsibleState = CollapsibleState.Collapsed;
public contextValue = Node.makeContextValue('QUICKPICK', 'clearCache', 'filterPackages', 'showOnlyFavorites', 'unsummarizeTopics');
// Node
declare public children?: PackageNode[];
// quickpick
public qpPrompt = 'Please select a package.';
// PkgRootNode
public showOnlyFavorites: boolean = false;
public filterText?: string;
public summarizeTopics: boolean = true;
async _handleCommand(cmd: cmdName){
if(cmd === 'clearCache'){
// used e.g. after manually installing/removing a package
this.refresh(true);
} else if(cmd === 'showOnlyFavorites'){
this.showOnlyFavorites = true;
this.iconPath = new vscode.ThemeIcon('star-full');
this.replaceContextValue('showOnlyFavorites', 'showAllPackages');
this.refresh();
} else if(cmd === 'showAllPackages'){
this.showOnlyFavorites = false;
this.iconPath = new vscode.ThemeIcon('list-unordered');
this.replaceContextValue('showAllPackages', 'showOnlyFavorites');
this.refresh();
} else if(cmd === 'filterPackages'){
// use validation function to continuously update filtered packages
const validateInput = (value: string) => {
this.filterText = value;
this.refresh();
return '';
};
// let user input filter text
this.filterText = await vscode.window.showInputBox({
validateInput: validateInput,
value: this.filterText,
});
this.description = (this.filterText ? `"${this.filterText}"` : '');
this.refresh();
} else if(cmd === 'unsummarizeTopics'){
this.summarizeTopics = false;
this.replaceContextValue('unsummarizeTopics', 'summarizeTopics');
this.refreshChildren(); // clears the 'grandchildren'
this.refresh(false, false);
} else if(cmd === 'summarizeTopics'){
this.summarizeTopics = true;
this.replaceContextValue('summarizeTopics', 'unsummarizeTopics');
this.refreshChildren(); // clears the 'grandchildren'
this.refresh(false, false);
}
}
refresh(clearCache: boolean = false, refreshChildren: boolean = true){
if(clearCache){
this.wrapper.rHelp.clearCachedFiles(`/doc/html/packages.html`);
void this.wrapper.rHelp.packageManager.clearCachedFiles(`/doc/html/packages.html`);
}
super.refresh(refreshChildren);
}
async makeChildren() {
let packages = await this.wrapper.rHelp.packageManager.getPackages(false);
if(!packages){
return [];
}
if(this.filterText){
const re = new RegExp(this.filterText);
packages = packages.filter(pkg => re.exec(pkg.name));
}
// favorites at the top
const children = packages.filter(pkg => pkg.isFavorite);
// nonFavorites below (if shown)
if(!this.showOnlyFavorites){
children.push(...packages.filter(pkg => !pkg.isFavorite));
}
// make packageNode for each child
return children.map(
pkg => new PackageNode(this, pkg)
);
}
}
// contains the topics belonging to an individual package
export class PackageNode extends NonRootNode {
// TreeItem
public command = undefined;
public collapsibleState = CollapsibleState.Collapsed;
public contextValue = Node.makeContextValue('QUICKPICK', 'clearCache', 'removePackage', 'updatePackage');
// QuickPick
public qpPrompt = 'Please select a Topic.';
// Package
public pkg: Package;
constructor(parent: PkgRootNode, pkg: Package){
super(parent);
this.pkg = pkg;
this.label = pkg.name;
this.tooltip = pkg.description;
this.qpDetail = pkg.description;
if(this.pkg.isFavorite){
this.addContextValues('removeFromFavorites');
} else{
this.addContextValues('addToFavorites');
}
if(this.pkg.isFavorite && !this.rootNode.pkgRootNode?.showOnlyFavorites){
this.iconPath = new vscode.ThemeIcon('star-full');
}
}
public async _handleCommand(cmd: cmdName): Promise<void> {
if(cmd === 'clearCache'){
// useful e.g. when working on a package
this.wrapper.rHelp.clearCachedFiles(new RegExp(`^/library/${this.pkg.name}/`));
this.refresh();
} else if(cmd === 'addToFavorites'){
this.wrapper.rHelp.packageManager.addFavorite(this.pkg.name);
this.parent.refresh();
} else if(cmd === 'removeFromFavorites'){
this.wrapper.rHelp.packageManager.removeFavorite(this.pkg.name);
this.parent.refresh();
} else if(cmd === 'updatePackage'){
const success = await this.wrapper.rHelp.packageManager.installPackages([this.pkg.name]);
// only reinstall if user confirmed removing the package (success === true)
// might still refresh if install was attempted but failed
if(success){
this.parent.refresh(true);
}
} else if(cmd === 'removePackage'){
const success = await this.wrapper.rHelp.packageManager.removePackage(this.pkg.name);
// only refresh if user confirmed removing the package (success === true)
// might still refresh if removing was attempted but failed
if(success){
this.parent.refresh(true);
}
}
}
async makeChildren(forQuickPick: boolean = false): Promise<TopicNode[]> {
const summarizeTopics = (
forQuickPick ? false : (this.rootNode.pkgRootNode?.summarizeTopics ?? true)
);
const topics = await this.wrapper.rHelp.packageManager.getTopics(this.pkg.name, summarizeTopics);
const ret = topics?.map(topic => new TopicNode(this, topic)) || [];
return ret;
}
}
// Node representing an individual topic/help page
class TopicNode extends NonRootNode {
// TreeItem
iconPath = new vscode.ThemeIcon('circle-filled');
contextValue = Node.makeContextValue('openInNewPanel');
// Topic
topic: Topic;
static iconPaths = new Map<TopicType, string>([
[TopicType.HOME, 'home'],
[TopicType.INDEX, 'list-unordered'],
[TopicType.META, 'file-code'],
[TopicType.NORMAL, 'circle-filled']
]);
protected _handleCommand(cmd: cmdName){
if(cmd === 'CALLBACK'){
void this.wrapper.rHelp.showHelpForPath(this.topic.helpPath);
} else if(cmd === 'openInNewPanel'){
void this.wrapper.rHelp.makeNewHelpPanel();
void this.wrapper.rHelp.showHelpForPath(this.topic.helpPath);
}
}
constructor(parent: NonRootNode, topic: Topic){
super(parent);
this.topic = topic;
this.label = topic.name;
this.iconPath = new vscode.ThemeIcon(TopicNode.iconPaths.get(this.topic.type) || 'circle-filled');
if(this.topic.type === TopicType.NORMAL){
this.qpLabel = this.topic.name;
}
if(this.topic.aliases){
this.tooltip = `Aliases:\n - ${this.topic.aliases.join('\n - ')}`;
} else{
this.tooltip = this.topic.description;
}
}
}
/////////////
// Preview for documentation of local package
class PreviewPackageNode extends NonRootNode {
public label = 'Local Preview';
public collapsibleState = CollapsibleState.Collapsed;
public iconPath = new vscode.ThemeIcon('eye');
public command = undefined;
public contextValue = Node.makeContextValue('QUICKPICK', 'unsummarizeTopics');
public qpPrompt = 'Please select a Topic.'
public summarizeTopics: boolean = true;
public packageDir: string;
private helpPreview: RLocalHelpPreviewer;
constructor(parent: RootNode, helpPreview: RLocalHelpPreviewer){
super(parent);
this.helpPreview = helpPreview;
this.packageDir = helpPreview?.packageDir;
this.refreshMetaInfo();
}
_handleCommand(cmd: cmdName){
if(cmd === 'unsummarizeTopics'){
this.summarizeTopics = false;
this.replaceContextValue('unsummarizeTopics', 'summarizeTopics');
this.refreshChildren(); // clears the 'grandchildren'
this.refresh(true);
} else if(cmd === 'summarizeTopics'){
this.summarizeTopics = true;
this.replaceContextValue('summarizeTopics', 'unsummarizeTopics');
this.refreshChildren(); // clears the 'grandchildren'
this.refresh(true);
}
}
makeChildren(forQuickPick: boolean = false): TopicNode[] {
const summarizeTopics = (
forQuickPick ? false : (this.summarizeTopics ?? true)
);
const topics = this.helpPreview?.getTreeViewTopics(summarizeTopics) || [];
const ret = topics.map(topic => new TopicNode(this, topic)) || [];
return ret;
}
private refreshMetaInfo(): void {
this.label = `Preview: ${this.helpPreview.getPackageName()}`;
const pkgInfo = this.helpPreview.getPackageInfo();
const toolTipParts: string[] = [];
if(pkgInfo?.version){
toolTipParts.push('v' + pkgInfo.version);
}
if(pkgInfo?.title){
toolTipParts.push(pkgInfo.title);
}
this.tooltip = toolTipParts.join(' - ');
}
// Can be called by a method from the node itself or externally to refresh the node in the treeview
public refresh(refreshChildren: boolean = true){
this.refreshMetaInfo();
if(refreshChildren){
this.children = undefined;
}
this.wrapper.refreshNode(this);
}
}
/////////////
// The following nodes only implement an individual command each
class HomeNode extends NonRootNode {
label = 'Home';
collapsibleState = CollapsibleState.None;
iconPath = new vscode.ThemeIcon('home');
contextValue = Node.makeContextValue('openInNewPanel');
_handleCommand(cmd: cmdName){
if(cmd === 'openInNewPanel'){
void this.wrapper.rHelp.makeNewHelpPanel();
void this.wrapper.rHelp.showHelpForPath('doc/html/index.html');
}
}
callBack(){
void this.wrapper.rHelp.showHelpForPath('doc/html/index.html');
}
}
class Search1Node extends NonRootNode {
label = 'Open Help Topic using `?`';
iconPath = new vscode.ThemeIcon('zap');
callBack(){
void this.wrapper.rHelp.searchHelpByAlias();
}
}
class Search2Node extends NonRootNode {
label = 'Search Help Topics using `??`';
iconPath = new vscode.ThemeIcon('search');
callBack(){
void this.wrapper.rHelp.searchHelpByText();
}
}
class RefreshNode extends NonRootNode {
label = 'Clear Cache & Restart Help Server';
iconPath = new vscode.ThemeIcon('refresh');
async callBack(){
await doWithProgress(() => this.wrapper.rHelp.refresh(), this.wrapper.viewId);
this.rootNode.pkgRootNode?.refresh();
this.rootNode.refresh();
}
}
class OpenForSelectionNode extends NonRootNode {
label = 'Open Help Page for Selected Text';
iconPath = new vscode.ThemeIcon('symbol-key');
callBack(){
void this.wrapper.rHelp.openHelpForSelection();
}
}
class InstallPackageNode extends NonRootNode {
label = 'Install CRAN Package';
iconPath = new vscode.ThemeIcon('cloud-download');
contextValue = Node.makeContextValue('installPackages', 'updateInstalledPackages');
public async _handleCommand(cmd: cmdName){
if(cmd === 'installPackages'){
const ret = await this.wrapper.rHelp.packageManager.pickAndInstallPackages(true);
if(ret){
this.rootNode.pkgRootNode?.refresh(true);
}
} else if(cmd === 'updateInstalledPackages'){
const ret = await this.wrapper.rHelp.packageManager.updatePackages();
if(ret){
this.rootNode.pkgRootNode?.refresh(true);
}
}
}
async callBack(){
await this.wrapper.rHelp.packageManager.pickAndInstallPackages();
this.rootNode.pkgRootNode?.refresh(true);
}
}