Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omnibox: open results locally if possible #6781

Merged
merged 3 commits into from
Jan 24, 2025
Merged

Conversation

camdencheek
Copy link
Member

@camdencheek camdencheek commented Jan 23, 2025

This modifies the behavior of clicking search results to link to local files if the result represents a file in your local repo. With the recent changes that heavily prefer results from your current repo, this should now be most results.

Test plan

Video walkthrough

@camdencheek camdencheek marked this pull request as ready for review January 23, 2025 20:52
const selectionStart = this.lineParamToRange(lineNumberParam).start
// Opening the file with an active selection is awkward, so use a zero-length
// selection to focus the target line without highlighting anything
const selection = new vscode.Range(selectionStart, selectionStart)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the scenario if the file has been locally modified, meaning the range we'd highlight here doesn't actually match the search result? Should we check for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know how we can check for this? I guess there can be all sorts of reasons why the local is different from the search result (search index behind, additional local commits that touch the file, different branch checked out locally (not sure we cannot for this in search), uncommitted changes...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, this is definitely an unfortunate side effect of search not being aware of local changes or non-main branches. However, since we're not actually selecting anything (zero-length selection that just scrolls the line into view), it won't be blatantly obvious that we jumped to a (hopefully) subtly wrong place. The worst case scenario is that the user is shown the wrong part of the file. If the file doesn't exist, we'll fall back to showing the remote content.

It would be possible to check for this (comparing local checkout against default branch), but that's a ton more work and I think this provides an immediately better experience for the 90%+ case.

vscode/src/chat/chat-view/ChatController.ts Outdated Show resolved Hide resolved
const selectionStart = this.lineParamToRange(lineNumberParam).start
// Opening the file with an active selection is awkward, so use a zero-length
// selection to focus the target line without highlighting anything
const selection = new vscode.Range(selectionStart, selectionStart)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know how we can check for this? I guess there can be all sorts of reasons why the local is different from the search result (search index behind, additional local commits that touch the file, different branch checked out locally (not sure we cannot for this in search), uncommitted changes...

@fkling fkling self-requested a review January 24, 2025 08:53
@camdencheek camdencheek merged commit 7ed51f2 into main Jan 24, 2025
19 of 21 checks passed
@camdencheek camdencheek deleted the cc/open-local-file branch January 24, 2025 16:47
camdencheek added a commit that referenced this pull request Jan 24, 2025
Backport request details: this is a low-risk, high-impact UX change that
significantly improves the usefulness of omnibox search results by
linking the local version of a file instead of a read-only view of the
file from Sourcegraph.

This modifies the behavior of clicking search results to link to local
files if the result represents a file in your local repo. With the
[recent changes](sourcegraph/sourcegraph#2943)
that heavily prefer results from your current repo, this should now be
most results.

## Test plan

[Video walkthrough](https://share.cleanshot.com/kqr06zwK)
 <br> Backport 7ed51f2 from #6781

Co-authored-by: Camden Cheek <[email protected]>
camdencheek added a commit that referenced this pull request Jan 24, 2025
…6799)

Backport request details: this is a low-risk, high-impact UX change that
significantly improves the usefulness of omnibox search results by
linking the local version of a file instead of a read-only view of the
file from Sourcegraph.

This modifies the behavior of clicking search results to link to local
files if the result represents a file in your local repo. With the
[recent changes](sourcegraph/sourcegraph#2943)
that heavily prefer results from your current repo, this should now be
most results.

## Test plan

[Video walkthrough](https://share.cleanshot.com/kqr06zwK)
 <br> Backport 7ed51f2 from #6781

Co-authored-by: Camden Cheek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants