mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
fix debt/issue with symbol navigation for inline hints (#162545)
This commit is contained in:
parent
c6313652fb
commit
35c9252094
|
@ -79,9 +79,11 @@ export abstract class SymbolNavigationAction extends EditorAction2 {
|
|||
private static _allSymbolNavigationCommands = new Map<string, SymbolNavigationAction>();
|
||||
private static _activeAlternativeCommands = new Set<string>();
|
||||
|
||||
readonly configuration: SymbolNavigationActionConfig;
|
||||
static all(): IterableIterator<SymbolNavigationAction> {
|
||||
return SymbolNavigationAction._allSymbolNavigationCommands.values();
|
||||
}
|
||||
|
||||
private static aaa(opts: IAction2Options): IAction2Options {
|
||||
private static _patchConfig(opts: IAction2Options): IAction2Options {
|
||||
const result = { ...opts, f1: true };
|
||||
// patch context menu when clause
|
||||
if (result.menu) {
|
||||
|
@ -95,8 +97,10 @@ export abstract class SymbolNavigationAction extends EditorAction2 {
|
|||
return result;
|
||||
}
|
||||
|
||||
readonly configuration: SymbolNavigationActionConfig;
|
||||
|
||||
constructor(configuration: SymbolNavigationActionConfig, opts: IAction2Options) {
|
||||
super(SymbolNavigationAction.aaa(opts));
|
||||
super(SymbolNavigationAction._patchConfig(opts));
|
||||
this.configuration = configuration;
|
||||
SymbolNavigationAction._allSymbolNavigationCommands.set(opts.id, this);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import * as dom from 'vs/base/browser/dom';
|
|||
import { Action, IAction, Separator } from 'vs/base/common/actions';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Location } from 'vs/editor/common/languages';
|
||||
|
@ -16,7 +15,7 @@ import { DefinitionAction, SymbolNavigationAction, SymbolNavigationAnchor } from
|
|||
import { ClickLinkMouseEvent } from 'vs/editor/contrib/gotoSymbol/browser/link/clickLinkGesture';
|
||||
import { RenderedInlayHintLabelPart } from 'vs/editor/contrib/inlayHints/browser/inlayHintsController';
|
||||
import { PeekContext } from 'vs/editor/contrib/peekView/browser/peekView';
|
||||
import { isIMenuItem, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { isIMenuItem, MenuId, MenuItemAction, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
|
||||
|
@ -41,13 +40,13 @@ export async function showGoToContextMenu(accessor: ServicesAccessor, editor: IC
|
|||
const menuActions: IAction[] = [];
|
||||
|
||||
// from all registered (not active) context menu actions select those
|
||||
// that are a symbol navigation action
|
||||
// that are a symbol navigation actions
|
||||
const filter = new Set(MenuRegistry.getMenuItems(MenuId.EditorContext)
|
||||
.map(item => isIMenuItem(item) ? item.command.id : ''));
|
||||
|
||||
for (const delegate of EditorExtensionsRegistry.getEditorActions()) {
|
||||
if (delegate instanceof SymbolNavigationAction && filter.has(delegate.id)) {
|
||||
menuActions.push(new Action(delegate.id, delegate.label, undefined, true, async () => {
|
||||
for (const delegate of SymbolNavigationAction.all()) {
|
||||
if (filter.has(delegate.desc.id)) {
|
||||
menuActions.push(new Action(delegate.desc.id, MenuItemAction.label(delegate.desc, { renderShortTitle: true }), undefined, true, async () => {
|
||||
const ref = await resolverService.createModelReference(location.uri);
|
||||
try {
|
||||
await instaService.invokeFunction(delegate.run.bind(delegate), editor, new SymbolNavigationAnchor(ref.object.textEditorModel, Range.getStartPosition(location.range)));
|
||||
|
|
|
@ -397,6 +397,12 @@ export interface IMenuItemHide {
|
|||
// subscribes to events of Action or modified properties
|
||||
export class MenuItemAction implements IAction {
|
||||
|
||||
static label(action: ICommandAction, options?: IMenuActionOptions): string {
|
||||
return options?.renderShortTitle && action.shortTitle
|
||||
? (typeof action.shortTitle === 'string' ? action.shortTitle : action.shortTitle.value)
|
||||
: (typeof action.title === 'string' ? action.title : action.title.value);
|
||||
}
|
||||
|
||||
readonly item: ICommandAction;
|
||||
readonly alt: MenuItemAction | undefined;
|
||||
|
||||
|
@ -418,9 +424,7 @@ export class MenuItemAction implements IAction {
|
|||
@ICommandService private _commandService: ICommandService
|
||||
) {
|
||||
this.id = item.id;
|
||||
this.label = options?.renderShortTitle && item.shortTitle
|
||||
? (typeof item.shortTitle === 'string' ? item.shortTitle : item.shortTitle.value)
|
||||
: (typeof item.title === 'string' ? item.title : item.title.value);
|
||||
this.label = MenuItemAction.label(item, options);
|
||||
this.tooltip = (typeof item.tooltip === 'string' ? item.tooltip : item.tooltip?.value) ?? '';
|
||||
this.enabled = !item.precondition || contextKeyService.contextMatchesRules(item.precondition);
|
||||
this.checked = undefined;
|
||||
|
|
Loading…
Reference in a new issue