From 386459dec0490aed8a67a1b94dc978a3307982eb Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 7 Dec 2022 15:22:52 +0100 Subject: [PATCH] fix https://github.com/microsoft/vscode/issues/146171 (#168307) --- extensions/references-view/src/calls/model.ts | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/extensions/references-view/src/calls/model.ts b/extensions/references-view/src/calls/model.ts index ce8cbbcf973..30d320355aa 100644 --- a/extensions/references-view/src/calls/model.ts +++ b/extensions/references-view/src/calls/model.ts @@ -180,13 +180,34 @@ class CallItemDataProvider implements vscode.TreeDataProvider { item.tooltip = item.label ? `${item.label} - ${element.item.detail}` : element.item.detail; item.contextValue = 'call-item'; item.iconPath = getThemeIcon(element.item.kind); + + type OpenArgs = [vscode.Uri, vscode.TextDocumentShowOptions]; + let openArgs: OpenArgs; + + if (element.model.direction === CallsDirection.Outgoing) { + + openArgs = [element.item.uri, { selection: element.item.selectionRange.with({ end: element.item.selectionRange.start }) }]; + + } else { + // incoming call -> reveal first call instead of caller + let firstLoctionStart: vscode.Position | undefined; + if (element.locations) { + for (const loc of element.locations) { + if (loc.uri.toString() === element.item.uri.toString()) { + firstLoctionStart = firstLoctionStart?.isBefore(loc.range.start) ? firstLoctionStart : loc.range.start; + } + } + } + if (!firstLoctionStart) { + firstLoctionStart = element.item.selectionRange.start; + } + openArgs = [element.item.uri, { selection: new vscode.Range(firstLoctionStart, firstLoctionStart) }]; + } + item.command = { command: 'vscode.open', title: vscode.l10n.t('Open Call'), - arguments: [ - element.item.uri, - { selection: element.item.selectionRange.with({ end: element.item.selectionRange.start }) } - ] + arguments: openArgs }; item.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed; return item;