Skip to content

Fix handling of Go-to-Commands to always call editor.action.goToLocations#5896

Merged
DanTup merged 5 commits intomasterfrom
fix-go-to-command
Feb 2, 2026
Merged

Fix handling of Go-to-Commands to always call editor.action.goToLocations#5896
DanTup merged 5 commits intomasterfrom
fix-go-to-command

Conversation

@DanTup
Copy link
Member

@DanTup DanTup commented Jan 30, 2026

Previously when there was only a single result, we'd bypass VS Code and compute the target editor ourselves which led to #5894

This way, we always let VS Code determine the target editor.

Fixes #5894

@DanTup DanTup added this to the v3.130.0 milestone Jan 30, 2026
@DanTup DanTup added is bug fix in editor Relates to code editing or language features labels Jan 30, 2026
@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.44%. Comparing base (c0387d2) to head (9cd4348).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/extension/lsp/go_to.ts 91.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5896      +/-   ##
==========================================
+ Coverage   67.39%   67.44%   +0.04%     
==========================================
  Files         168      168              
  Lines       12918    12925       +7     
  Branches     2559     2560       +1     
==========================================
+ Hits         8706     8717      +11     
+ Misses       3758     3754       -4     
  Partials      454      454              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ions

Previously when there was only a single result, we'd bypass VS Code and compute the target editor ourselves which led to #5894

This way, we always let VS Code determine the target editor.

Fixes #5894
We've moved to VS Code's goToLocation command, which flashes the range, but leaves the selection at just the start.
... but looking at current editor first.

We don't have a source document/position when the server calls `goToLocation` so it needs the original implementation. We just shouldn't be doing it in the case where we have a set of results, even if there is only one in there.
@DanTup DanTup force-pushed the fix-go-to-command branch from 325719c to 3138b88 Compare February 2, 2026 12:01
We can't try to search for a range in a document if it might not be open yet, so we need to wait on the whole operation not just the equality check.
@DanTup DanTup requested a review from Copilot February 2, 2026 12:54
@DanTup
Copy link
Member Author

DanTup commented Feb 2, 2026

@codex review

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement, unifying the 'Go-to' commands to consistently use editor.action.goToLocations. This simplifies the code and fixes a bug with multi-group editor layouts by delegating editor management to VS Code. The refactoring of the base LspGoToCommand and its subclasses is clean, and the introduction of failureMessage makes the commands more robust. The test updates are also solid, using waitForResult to improve reliability.

I've added one suggestion for LspGoToLocationCommand to further simplify the code and align it with the PR's goal of avoiding manual editor navigation.

Comment on lines +123 to +139
protected async goToLocation(location: ls.Location): Promise<void> {
const codeLocation = this.analyzer.client.protocol2CodeConverter.asLocation(location);
const uri = codeLocation.uri;
const elementDocument = await vs.workspace.openTextDocument(uri);

let editor = vs.window.activeTextEditor?.document === elementDocument ? vs.window.activeTextEditor : undefined;
if (!editor) {
const sourceUriString = uriComparisonString(uri);
const existingTab = vs.window.tabGroups.all
.flatMap((group) => group.tabs)
.find((tab) => tab.input instanceof vs.TabInputText && uriComparisonString(tab.input.uri) === sourceUriString);
const tabGroup = existingTab?.group.viewColumn;

editor = await vs.window.showTextDocument(elementDocument, tabGroup);
}
showCode(editor, codeLocation.range, codeLocation.range, codeLocation.range);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation of goToLocation re-introduces manual editor and tab group management, which the pull request description identifies as a source of bugs. While editor.action.goToLocations might not be suitable here due to the lack of a source position, the logic can be greatly simplified by using vs.window.showTextDocument with options. This would delegate editor handling to VS Code, aligning with the goal of this PR and making the code less prone to bugs related to multi-group editor layouts.

	protected async goToLocation(location: ls.Location): Promise<void> {
		const codeLocation = this.analyzer.client.protocol2CodeConverter.asLocation(location);
		await vs.window.showTextDocument(codeLocation.uri, { selection: codeLocation.range });
	}

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DanTup DanTup merged commit f60f0af into master Feb 2, 2026
33 checks passed
@DanTup DanTup deleted the fix-go-to-command branch February 2, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in editor Relates to code editing or language features is bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go to Imports moves to different editor

2 participants