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

Fix picker preview #8265

Merged
merged 2 commits into from
Sep 14, 2023
Merged

Fix picker preview #8265

merged 2 commits into from
Sep 14, 2023

Conversation

pascalkuthe
Copy link
Member

This PR fixes some issues with the picker preview.

Firstly it fixes a panic when previewing invalid ranges in the picker by simply only showing a placeholder in this case. Closes #8259.

While investigating this I noticed that #7837 had introduced a regression. In the past the picker centered all previewed ranges. However, after that PR only the fist line (instead of the middle of the previewed ranges) was centered.

I misread what the old code and therefore didn't notice during review. The second commit in this PR restores that behavior (can be easily tested by searching for Modifier in the global symbol picker in helix codebase) while keeping the soft wrap compatibility added by #7837.

Adding to the release milestone since it's an easy fix for a crash plus a fix for a regression in the second commit.

@pascalkuthe pascalkuthe added this to the 23.9 milestone Sep 12, 2023
@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Sep 12, 2023
the-mikedavis
the-mikedavis previously approved these changes Sep 12, 2023
Comment on lines 115 to 117
Self::EditorDocument(_) => "<Invalid File Location>",
Self::Cached(preview) => match preview {
CachedPreview::Document(_) => "<File preview>",
CachedPreview::Document(_) => "<Invalid File Location>",
Copy link
Member

Choose a reason for hiding this comment

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

Why the change? Casing should match the rest of the variants

Copy link
Member Author

@pascalkuthe pascalkuthe Sep 13, 2023

Choose a reason for hiding this comment

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

I fixed the casing.

These branches were actually unreachable so far. We only show the placeholder if preview.document() returns None which doesn't happen for these two cases:

    fn document(&self) -> Option<&Document> {
        match self {
            Preview::EditorDocument(doc) => Some(doc),
            Preview::Cached(CachedPreview::Document(doc)) => Some(doc),
            _ => None,
        }
    }

However, with this PR we also show the placeholder if range is invalid so the only way to endup in this branch is if the location provided by whatever the picker is previewing is invalid (usually a problem with the LSP but for global search the file could also have been changed by another process since the initial search ran).

A way to make this a bit cleaner would be to document() to have the following signature:

 /// Returns the document to preview if available or a placeholder string otherwise
 fn document(&self) -> Result<&Document, &str>

but I wanted to keep the change minimal here.

@archseer archseer merged commit 13d4463 into master Sep 14, 2023
@archseer archseer deleted the picker_preview branch September 14, 2023 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash while browsing workspace symbol picker
3 participants