Skip to content

Commit 84ca054

Browse files
author
Hannia Valera
committed
preventing "eager" bookmarks tree view
1 parent 48b4729 commit 84ca054

1 file changed

Lines changed: 47 additions & 5 deletions

File tree

src/extension.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ export class ExtensionManager implements vscode.Disposable {
325325
}
326326
}
327327

328+
public onFullFeatureSetChanged(fullFeatureSet: boolean) {
329+
if (fullFeatureSet) {
330+
this.ensureBookmarksTreeView();
331+
} else {
332+
this.disposeBookmarksTreeView();
333+
}
334+
}
335+
328336
public onExtensionActiveCommandsChanged(listener: () => any, thisObject: any | null) {
329337
this.extensionActiveCommandsEmitter.event(listener, thisObject);
330338
}
@@ -403,10 +411,43 @@ export class ExtensionManager implements vscode.Disposable {
403411
* The bookmarks tree data provider
404412
*/
405413
private readonly bookmarksProvider = new BookmarksProvider(this.extensionContext);
406-
private readonly bookmarksTreeView = vscode.window.createTreeView('cmake.bookmarks', {
407-
treeDataProvider: this.bookmarksProvider,
408-
showCollapseAll: false
409-
});
414+
private bookmarksTreeView?: vscode.TreeView<BaseNode>;
415+
416+
private ensureBookmarksTreeView() {
417+
if (this.bookmarksTreeView) {
418+
return;
419+
}
420+
421+
if (!this.isBookmarksViewContributed()) {
422+
log.debug('Skipping bookmarks tree creation because view contribution is not available.');
423+
return;
424+
}
425+
426+
try {
427+
this.bookmarksTreeView = vscode.window.createTreeView('cmake.bookmarks', {
428+
treeDataProvider: this.bookmarksProvider,
429+
showCollapseAll: false
430+
});
431+
} catch (err) {
432+
log.error('Failed to create bookmarks tree view', err as Error);
433+
}
434+
}
435+
436+
private disposeBookmarksTreeView() {
437+
if (this.bookmarksTreeView) {
438+
this.bookmarksTreeView.dispose();
439+
this.bookmarksTreeView = undefined;
440+
}
441+
}
442+
443+
private isBookmarksViewContributed(): boolean {
444+
const ext = vscode.extensions.getExtension('ms-vscode.cmake-tools');
445+
const views = ext?.packageJSON?.contributes?.views;
446+
if (!views) {
447+
return false;
448+
}
449+
return Object.values(views).some((v: any) => Array.isArray(v) && v.some((item: any) => item?.id === 'cmake.bookmarks'));
450+
}
410451

411452
/**
412453
* CppTools project configuration provider. Tells cpptools how to search for
@@ -677,7 +718,7 @@ export class ExtensionManager implements vscode.Disposable {
677718
this.onDidChangeActiveTextEditorSub.dispose();
678719
void this.kitsWatcher.close();
679720
this.projectOutlineTreeView.dispose();
680-
this.bookmarksTreeView.dispose();
721+
this.disposeBookmarksTreeView();
681722
this.extensionActiveCommandsEmitter.dispose();
682723
pinnedCommands.dispose();
683724
if (this.cppToolsAPI) {
@@ -2651,6 +2692,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<api.CM
26512692
// The scope of this is the whole workspace.
26522693
export async function enableFullFeatureSet(fullFeatureSet: boolean) {
26532694
await setContextAndStore("cmake:enableFullFeatureSet", fullFeatureSet);
2695+
extensionManager?.onFullFeatureSetChanged(fullFeatureSet);
26542696
extensionManager?.showStatusBar(fullFeatureSet);
26552697
}
26562698

0 commit comments

Comments
 (0)