提交 dd1c9908 编写于 作者: B Benjamin Pasero

resourceScheme context does not work in in menu.commandPalette contribution (fixes #28211)

上级 7b812736
......@@ -30,7 +30,7 @@ import { IEditorPart } from 'vs/workbench/services/editor/browser/editorService'
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { Position, POSITIONS, Direction } from 'vs/platform/editor/common/editor';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IMessageService, IMessageWithAction, Severity } from 'vs/platform/message/common/message';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
......@@ -44,6 +44,7 @@ import { EDITOR_GROUP_BACKGROUND } from 'vs/workbench/common/theme';
import { createCSSRule } from 'vs/base/browser/dom';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { join } from 'vs/base/common/paths';
import { isCommonCodeEditor } from 'vs/editor/common/editorCommon';
class ProgressMonitor {
......@@ -1298,6 +1299,20 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
}
}
public invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
const activeEditor = this.getActiveEditor();
if (activeEditor) {
const activeEditorControl = activeEditor.getControl();
if (isCommonCodeEditor(activeEditorControl)) {
return activeEditorControl.invokeWithinContext(fn);
}
return this.editorGroupsControl.getInstantiationService(activeEditor.position).invokeFunction(fn);
}
return this.instantiationService.invokeFunction(fn);
}
public layout(dimension: Dimension): Dimension[] {
// Pass to super
......
......@@ -19,7 +19,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { Registry } from 'vs/platform/registry/common/platform';
import { QuickOpenHandler, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen';
import { IEditorAction, IEditor, isCommonCodeEditor, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { IEditorAction, IEditor, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { matchesWords, matchesPrefix, matchesContiguousSubString, or } from 'vs/base/common/filters';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
......@@ -34,6 +34,7 @@ import { once } from 'vs/base/common/event';
import { BoundedMap, ISerializedBoundedLinkedMap } from 'vs/base/common/map';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
export const ALL_COMMANDS_PREFIX = '>';
......@@ -385,6 +386,7 @@ export class CommandsHandler extends QuickOpenHandler {
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IInstantiationService private instantiationService: IInstantiationService,
@IKeybindingService private keybindingService: IKeybindingService,
@IMenuService private menuService: IMenuService,
......@@ -427,10 +429,7 @@ export class CommandsHandler extends QuickOpenHandler {
const editorEntries = this.editorActionsToEntries(editorActions, searchValue);
// Other Actions
const menu = isCommonCodeEditor(activeEditorControl)
? activeEditorControl.invokeWithinContext(accessor => this.menuService.createMenu(MenuId.CommandPalette, accessor.get(IContextKeyService)))
: this.menuService.createMenu(MenuId.CommandPalette, this.contextKeyService);
const menu = this.editorGroupService.invokeWithinEditorContext(accessor => this.menuService.createMenu(MenuId.CommandPalette, accessor.get(IContextKeyService)));
const menuActions = menu.getActions().reduce((r, [, actions]) => [...r, ...actions], <MenuItemAction[]>[]);
const commandEntries = this.menuItemActionsToEntries(menuActions, searchValue);
......
......@@ -5,7 +5,7 @@
'use strict';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Position, IEditorInput } from 'vs/platform/editor/common/editor';
import { IEditorStacksModel, IEditorGroup } from 'vs/workbench/common/editor';
import Event from 'vs/base/common/event';
......@@ -132,4 +132,9 @@ export interface IEditorGroupService {
* Returns tab options.
*/
getTabOptions(): IEditorTabOptions;
/**
* Invoke a function in the context of the active editor.
*/
invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T;
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ import { EnvironmentService } from 'vs/platform/environment/node/environmentServ
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IWindowsService, IWindowService, INativeOpenDialogOptions } from 'vs/platform/windows/common/windows';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
......@@ -556,6 +556,10 @@ export class TestEditorGroupService implements IEditorGroupService {
public getTabOptions(): IEditorTabOptions {
return {};
}
public invokeWithinEditorContext<T>(fn: (accessor: ServicesAccessor) => T): T {
return fn(null);
}
}
export class TestEditorService implements IWorkbenchEditorService {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册