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

Rust Analyzer: Inlay hint fragments apply in reverse order #7928

Open
1 task done
listochkin opened this issue Feb 16, 2024 · 2 comments
Open
1 task done

Rust Analyzer: Inlay hint fragments apply in reverse order #7928

listochkin opened this issue Feb 16, 2024 · 2 comments
Labels
defect [core label] inlay hints language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors rust Rust programming language support

Comments

@listochkin
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Rust Analyzer has optional hints for closure captures. When enabled Zed shows their fragments in reverse order.

Version: Zed 0.122.2 a1c5d027319bd80ae348fa3ce2be22c2a6785284

Steps to reproduce:

  1. Adjust your editor settings:
"inlay_hints": {
  "enabled": true,
},
"lsp": {
  "rust-analyzer": {
    "initialization_options": {
      "inlayHints": {
        "closureCaptureHints": {
          "enable": true
        }
      }
    }
  }
}
  1. Create a new Rust project cargo new inlay-hints-reverse-fragments, replace the code in main.rs with the following:
fn main() {
    let x = 42;
    std::thread::scope(|s| {
        s.spawn(|| {
            let _x = x;
        });
    });
}

Results:

(I put hints in comments to keep GitHub Syntax highlighter happy):

// Expected
std::thread::scope(/* move (&x) */|s| {
// Actual
std::thread::scope(/* &x) (move */|s| {

You can see how fragments of hints get applied in reverse order. Also, As I type code (just add spaces at the end) I sometimes see them flicker, extra parenthesis may show up or hide, etc. Seems like some inconsistencies during updates, but most likely an unrelated issue.

VSCode shows these hints correctly, as do unit tests in Rust Analyzer repo: https://github.com/rust-lang/rust-analyzer/blob/ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d/crates/ide/src/inlay_hints/closure_captures.rs#L143

Environment

Zed: v0.122.2 (Zed)
OS: macOS 12.7.3
Memory: 32 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

No response

@listochkin listochkin added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Feb 16, 2024
@SomeoneToIgnore
Copy link
Contributor

Relevant LSP response part:

[
        {
            "position": {
                "line": 73,
                "character": 16
            },
            "label": "move",
            "paddingLeft": false,
            "paddingRight": false
        },
        {
            "position": {
                "line": 73,
                "character": 16
            },
            "label": "(",
            "paddingLeft": false,
            "paddingRight": false
        },
        {
            "position": {
                "line": 73,
                "character": 16
            },
            "label": [
                {
                    "value": "&x"
                }
            ],
            "paddingLeft": false,
            "paddingRight": false,
            "data": {
                "file_id": 0
            }
        },
        {
            "position": {
                "line": 73,
                "character": 16
            },
            "label": ")",
            "paddingLeft": false,
            "paddingRight": true
        },
    ]

looks like all those hints belong to a single point in the real text, and Zed mixes them up during display.
It's hard to say without extra debugging, where does the issue come from, but instant suspicious place would be

let start_ix = match self.inlays.binary_search_by(|probe| {
probe
.position
.to_offset(&buffer_snapshot)
.cmp(&buffer_edit.new.start)
.then(std::cmp::Ordering::Greater)
}) {
Ok(ix) | Err(ix) => ix,
};

@JosephTLyons JosephTLyons added rust Rust programming language support language An umbrella label for all programming languages syntax behaviors language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Feb 20, 2024
@xvbcfj
Copy link

xvbcfj commented Aug 4, 2024

would be good if this gets fixed soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] inlay hints language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors rust Rust programming language support
Projects
None yet
Development

No branches or pull requests

4 participants