Skip to content

Commit

Permalink
Overlay context service need not implement dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Mar 9, 2023
1 parent 34652da commit 3bc0bd8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/vs/platform/actions/common/actions.ts
Expand Up @@ -11,7 +11,7 @@ import { LinkedList } from 'vs/base/common/linkedList';
import { ICommandAction, ICommandActionTitle, Icon, ILocalizedString } from 'vs/platform/action/common/action';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { CommandsRegistry, ICommandHandlerDescription, ICommandService } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpr, ContextKeyExpression, IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingRule, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';

Expand Down Expand Up @@ -238,7 +238,7 @@ export interface IMenuService {
* submenu entries. That is more expensive and must be explicitly enabled with the
* `emitEventsForSubmenuChanges` flag.
*/
createMenu(id: MenuId, contextKeyService: IContextKeyService, options?: IMenuCreateOptions): IMenu;
createMenu(id: MenuId, contextKeyService: IContextKeyService | IOverlayContextKeyService, options?: IMenuCreateOptions): IMenu;

/**
* Reset **all** menu item hidden states.
Expand Down
12 changes: 4 additions & 8 deletions src/vs/platform/contextkey/browser/contextKeyService.ts
Expand Up @@ -14,7 +14,7 @@ import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IReadableSet, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ContextKeyExpression, ContextKeyInfo, ContextKeyValue, IContext, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IOverlayContextKeyService, IReadableSet, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';

const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context';
Expand Down Expand Up @@ -308,7 +308,7 @@ export abstract class AbstractContextKeyService implements IContextKeyService {
return new ScopedContextKeyService(this, domNode);
}

createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService {
createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IOverlayContextKeyService {
if (this._isDisposed) {
throw new Error(`AbstractContextKeyService has been disposed`);
}
Expand Down Expand Up @@ -527,7 +527,7 @@ class OverlayContext implements IContext {
}
}

class OverlayContextKeyService implements IContextKeyService {
class OverlayContextKeyService implements IOverlayContextKeyService {

declare _serviceBrand: undefined;
private overlay: Map<string, any>;
Expand Down Expand Up @@ -575,17 +575,13 @@ class OverlayContextKeyService implements IContextKeyService {
throw new Error('Not supported.');
}

createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IContextKeyService {
createOverlay(overlay: Iterable<[string, any]> = Iterable.empty()): IOverlayContextKeyService {
return new OverlayContextKeyService(this, overlay);
}

updateParent(): void {
throw new Error('Not supported.');
}

dispose(): void {
// noop
}
}

function findContextAttr(domNode: IContextKeyServiceTarget | null): number {
Expand Down
4 changes: 3 additions & 1 deletion src/vs/platform/contextkey/common/contextkey.ts
Expand Up @@ -2031,6 +2031,8 @@ export interface IContextKeyChangeEvent {
allKeysContainedIn(keys: IReadableSet<string>): boolean;
}

export type IOverlayContextKeyService = Omit<IContextKeyService, 'dispose'>;

export interface IContextKeyService {
readonly _serviceBrand: undefined;
dispose(): void;
Expand All @@ -2043,7 +2045,7 @@ export interface IContextKeyService {
getContextKeyValue<T>(key: string): T | undefined;

createScoped(target: IContextKeyServiceTarget): IContextKeyService;
createOverlay(overlay: Iterable<[string, any]>): IContextKeyService;
createOverlay(overlay: Iterable<[string, any]>): IOverlayContextKeyService;
getContext(target: IContextKeyServiceTarget | null): IContext;

updateParent(parentContextKeyService: IContextKeyService): void;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/contextview/browser/contextView.ts
Expand Up @@ -9,7 +9,7 @@ import { IAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IMenuActionOptions, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

export const IContextViewService = createDecorator<IContextViewService>('contextViewService');
Expand Down Expand Up @@ -62,7 +62,7 @@ export type IContextMenuMenuDelegate = {
/**
* Optional context key service which drives the given menu
*/
contextKeyService?: IContextKeyService;
contextKeyService?: IContextKeyService | IOverlayContextKeyService;

/**
* Optional getter for extra actions. They will be prepended to the menu actions.
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/debug/browser/variablesView.ts
Expand Up @@ -214,7 +214,7 @@ export class VariablesView extends ViewPane {
const toDispose = new DisposableStore();

try {
const contextKeyService = toDispose.add(await getContextForVariableMenuWithDataAccess(this.contextKeyService, variable));
const contextKeyService = await getContextForVariableMenuWithDataAccess(this.contextKeyService, variable);
const menu = toDispose.add(this.menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService));

const context: IVariablesContext = getVariablesContext(variable);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/remote/browser/tunnelView.ts
Expand Up @@ -790,7 +790,7 @@ export class TunnelPanel extends ViewPane {
this.tunnelViewMultiSelectionContext = TunnelViewMultiSelectionContextKey.bindTo(contextKeyService);
this.portChangableContextKey = PortChangableContextKey.bindTo(contextKeyService);

const overlayContextKeyService = this._register(this.contextKeyService.createOverlay([['view', TunnelPanel.ID]]));
const overlayContextKeyService = this.contextKeyService.createOverlay([['view', TunnelPanel.ID]]);
const titleMenu = this._register(this.menuService.createMenu(MenuId.TunnelTitle, overlayContextKeyService));
const updateActions = () => {
this.titleActions = [];
Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts
Expand Up @@ -22,7 +22,7 @@ import { editorErrorForeground, registerColor, transparent } from 'vs/platform/t
import { ICodeEditor, IEditorMouseEvent, isCodeEditor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction, EditorContributionInstantiation } from 'vs/editor/browser/editorExtensions';
import { PeekViewWidget, getOuterEditor, peekViewBorder, peekViewTitleBackground, peekViewTitleForeground, peekViewTitleInfoForeground } from 'vs/editor/contrib/peekView/browser/peekView';
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Position } from 'vs/editor/common/core/position';
Expand Down Expand Up @@ -201,11 +201,12 @@ class DirtyDiffWidget extends PeekViewWidget {
this._disposables.add(themeService.onDidColorThemeChange(this._applyTheme, this));
this._applyTheme(themeService.getColorTheme());

let overlayContextKeyService: IOverlayContextKeyService | IContextKeyService = contextKeyService;
if (this.model.original.length > 0) {
contextKeyService = contextKeyService.createOverlay([['originalResourceScheme', this.model.original[0].uri.scheme], ['originalResourceSchemes', this.model.original.map(original => original.uri.scheme)]]);
overlayContextKeyService = contextKeyService.createOverlay([['originalResourceScheme', this.model.original[0].uri.scheme], ['originalResourceSchemes', this.model.original.map(original => original.uri.scheme)]]);
}

this.menu = menuService.createMenu(MenuId.SCMChangeContext, contextKeyService);
this.menu = menuService.createMenu(MenuId.SCMChangeContext, overlayContextKeyService);
this._disposables.add(this.menu);

this.create();
Expand Down
14 changes: 7 additions & 7 deletions src/vs/workbench/contrib/scm/browser/menus.ts
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./media/scm';
import { Emitter } from 'vs/base/common/event';
import { IDisposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IOverlayContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { IAction } from 'vs/base/common/actions';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
Expand Down Expand Up @@ -94,7 +94,7 @@ class SCMMenusItem implements IDisposable {
private contextualResourceMenus: Map<string /* contextValue */, IContextualResourceMenuItem> | undefined;

constructor(
private contextKeyService: IContextKeyService,
private contextKeyService: IOverlayContextKeyService,
private menuService: IMenuService
) { }

Expand Down Expand Up @@ -144,7 +144,7 @@ class SCMMenusItem implements IDisposable {

export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {

private contextKeyService: IContextKeyService;
private _overlayContextKeyService: IOverlayContextKeyService;

readonly titleMenu: SCMTitleMenu;
private readonly resourceGroups: ISCMResourceGroup[] = [];
Expand All @@ -153,7 +153,7 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {
private _repositoryMenu: IMenu | undefined;
get repositoryMenu(): IMenu {
if (!this._repositoryMenu) {
this._repositoryMenu = this.menuService.createMenu(MenuId.SCMSourceControl, this.contextKeyService);
this._repositoryMenu = this.menuService.createMenu(MenuId.SCMSourceControl, this._overlayContextKeyService);
this.disposables.add(this._repositoryMenu);
}

Expand All @@ -168,13 +168,13 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {
@IInstantiationService instantiationService: IInstantiationService,
@IMenuService private readonly menuService: IMenuService
) {
this.contextKeyService = contextKeyService.createOverlay([
this._overlayContextKeyService = contextKeyService.createOverlay([
['scmProvider', provider.contextValue],
['scmProviderRootUri', provider.rootUri?.toString()],
['scmProviderHasRootUri', !!provider.rootUri],
]);

const serviceCollection = new ServiceCollection([IContextKeyService, this.contextKeyService]);
const serviceCollection = new ServiceCollection([IContextKeyService, this._overlayContextKeyService]);
instantiationService = instantiationService.createChild(serviceCollection);
this.titleMenu = instantiationService.createInstance(SCMTitleMenu);

Expand All @@ -198,7 +198,7 @@ export class SCMRepositoryMenus implements ISCMRepositoryMenus, IDisposable {
let result = this.resourceGroupMenusItems.get(group);

if (!result) {
const contextKeyService = this.contextKeyService.createOverlay([
const contextKeyService = this._overlayContextKeyService.createOverlay([
['scmResourceGroup', group.id],
]);

Expand Down

0 comments on commit 3bc0bd8

Please sign in to comment.