prevent empty context menu entry, make sure to invoke commands with the correct anchor and correct range (#178804)

fixes https://github.com/microsoft/vscode/issues/174912
This commit is contained in:
Johannes Rieken 2023-03-31 15:52:43 +02:00 committed by GitHub
parent 86dade763c
commit 13562cc6f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@
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 { generateUuid } from 'vs/base/common/uuid';
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { Range } from 'vs/editor/common/core/range';
@ -42,14 +43,16 @@ export async function showGoToContextMenu(accessor: ServicesAccessor, editor: IC
// from all registered (not active) context menu actions select those
// that are a symbol navigation actions
const filter = new Set(MenuRegistry.getMenuItems(MenuId.EditorContext)
.map(item => isIMenuItem(item) ? item.command.id : ''));
.map(item => isIMenuItem(item) ? item.command.id : generateUuid()));
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)));
const symbolAnchor = new SymbolNavigationAnchor(ref.object.textEditorModel, Range.getStartPosition(location.range));
const range = part.item.anchor.range;
await instaService.invokeFunction(delegate.runEditorCommand.bind(delegate), editor, symbolAnchor, range);
} finally {
ref.dispose();