diff --git a/src/vs/workbench/contrib/positronMissingPackages/browser/positronMissingPackages.contribution.ts b/src/vs/workbench/contrib/positronMissingPackages/browser/positronMissingPackages.contribution.ts index 9fe9cc76765f..d8f831131955 100644 --- a/src/vs/workbench/contrib/positronMissingPackages/browser/positronMissingPackages.contribution.ts +++ b/src/vs/workbench/contrib/positronMissingPackages/browser/positronMissingPackages.contribution.ts @@ -52,15 +52,18 @@ workbenchRegistry.registerWorkbenchContribution(MissingPackagesPrecomputeContrib workbenchRegistry.registerWorkbenchContribution(MissingPackagesContextKeyContribution, LifecyclePhase.Restored); // Editor action bar badge (scenario 2) for scripts whose language has a session -// that supports missing packages, and Quarto documents. The editor action bar -// is disabled for notebooks, so notebooks get a separate mount below. Quarto -// documents are multi-language; the service splits them into per-language code -// chunks and routes each to its session. +// that supports missing packages, and Quarto documents. The Positron notebook +// toolbar also renders this menu, so notebooks are excluded here and get their +// own mount below. Quarto documents are multi-language; the service splits them +// into per-language code chunks and routes each to its session. PositronActionBarWidgetRegistry.registerWidget({ id: 'positronMissingPackages.editorBadge', menuId: MenuId.EditorActionsRight, order: 95, - when: MISSING_PACKAGES_SUPPORTED_KEY, + when: ContextKeyExpr.and( + MISSING_PACKAGES_SUPPORTED_KEY, + ContextKeyExpr.notEquals('activeEditor', POSITRON_NOTEBOOK_EDITOR_ID), + ), selfContained: true, componentFactory: (accessor) => () => React.createElement(MissingPackagesBadgeMount, { accessor }), }); diff --git a/src/vs/workbench/contrib/positronMissingPackages/test/browser/missingPackagesBadgeRegistration.vitest.ts b/src/vs/workbench/contrib/positronMissingPackages/test/browser/missingPackagesBadgeRegistration.vitest.ts new file mode 100644 index 000000000000..fd53f8a81830 --- /dev/null +++ b/src/vs/workbench/contrib/positronMissingPackages/test/browser/missingPackagesBadgeRegistration.vitest.ts @@ -0,0 +1,38 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2026 Posit Software, PBC. All rights reserved. + * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. + *--------------------------------------------------------------------------------------------*/ + +/// + +import { MenuId } from '../../../../../platform/actions/common/actions.js'; +import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js'; +import { PositronActionBarWidgetRegistry } from '../../../../../platform/positronActionBar/browser/positronActionBarWidgetRegistry.js'; +import { stubInterface } from '../../../../../test/vitest/stubInterface.js'; +import { POSITRON_NOTEBOOK_EDITOR_ID } from '../../../positronNotebook/common/positronNotebookCommon.js'; +import { MISSING_PACKAGES_SUPPORTED_KEY } from '../../browser/missingPackagesContextKey.js'; +// Registers the badge widgets as a side effect. +import '../../browser/positronMissingPackages.contribution.js'; + +function badgesFor(activeEditor: string): string[] { + const values: Record = { + activeEditor, + [MISSING_PACKAGES_SUPPORTED_KEY.key]: true, + }; + const contextKeyService = stubInterface({ + contextMatchesRules: rules => !rules || rules.evaluate({ getValue: (key: string) => values[key] as T }), + }); + return PositronActionBarWidgetRegistry.getWidgets(MenuId.EditorActionsRight, contextKeyService) + .map(w => w.id) + .filter(id => id.startsWith('positronMissingPackages.')); +} + +describe('missing packages badge registration', () => { + it('shows only the notebook badge in a Positron notebook', () => { + expect(badgesFor(POSITRON_NOTEBOOK_EDITOR_ID)).toEqual(['positronMissingPackages.notebookBadge']); + }); + + it('shows only the editor badge in a text editor', () => { + expect(badgesFor('workbench.editors.files.textFileEditor')).toEqual(['positronMissingPackages.editorBadge']); + }); +});