From a7d3488c108fc320b0521a24bab1a36c567f5cd8 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 14 Jan 2025 17:05:00 +0100 Subject: [PATCH] Hide legacy category from scope visualizer in fully migrated languages (#2727) When using the scope visualizer for a language that is fully migrated to our scope handlers I thought it was unnecessary that we showed an empty legacy category in the scope visualizer. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet --- .../src/ScopeTreeProvider.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/cursorless-vscode/src/ScopeTreeProvider.ts b/packages/cursorless-vscode/src/ScopeTreeProvider.ts index b9d1aa3d8b..75f3e20c8a 100644 --- a/packages/cursorless-vscode/src/ScopeTreeProvider.ts +++ b/packages/cursorless-vscode/src/ScopeTreeProvider.ts @@ -112,7 +112,7 @@ export class ScopeTreeProvider implements TreeDataProvider { getChildren(element?: MyTreeItem): MyTreeItem[] { if (element == null) { void this.possiblyShowUpdateTalonMessage(); - return getSupportCategories(); + return getSupportCategories(this.hasLegacyScopes()); } if (element instanceof SupportCategoryTreeItem) { @@ -156,7 +156,15 @@ export class ScopeTreeProvider implements TreeDataProvider { } } - getScopeTypesWithSupport(scopeSupport: ScopeSupport): ScopeSupportTreeItem[] { + private hasLegacyScopes(): boolean { + return this.supportLevels.some( + (supportLevel) => supportLevel.support === ScopeSupport.supportedLegacy, + ); + } + + private getScopeTypesWithSupport( + scopeSupport: ScopeSupport, + ): ScopeSupportTreeItem[] { return this.supportLevels .filter( (supportLevel) => @@ -202,11 +210,15 @@ export class ScopeTreeProvider implements TreeDataProvider { } } -function getSupportCategories(): SupportCategoryTreeItem[] { +function getSupportCategories( + includeLegacy: boolean, +): SupportCategoryTreeItem[] { return [ new SupportCategoryTreeItem(ScopeSupport.supportedAndPresentInEditor), new SupportCategoryTreeItem(ScopeSupport.supportedButNotPresentInEditor), - new SupportCategoryTreeItem(ScopeSupport.supportedLegacy), + ...(includeLegacy + ? [new SupportCategoryTreeItem(ScopeSupport.supportedLegacy)] + : []), new SupportCategoryTreeItem(ScopeSupport.unsupported), ]; }