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

Returns inlay hints outside requested region #14215

Open
joaotavora opened this issue Feb 27, 2023 · 1 comment
Open

Returns inlay hints outside requested region #14215

joaotavora opened this issue Feb 27, 2023 · 1 comment
Labels
A-inlay-hints inlay/inline hints C-bug Category: bug

Comments

@joaotavora
Copy link

rust-analyzer version: rust-analyzer 1 (a6603fc21 2023-02-16)

rustc version: rustc 1.67.1 (d5a82bbd2 2023-02-07) (Arch Linux rust 1:1.67.1-1)

relevant settings: No settings that I am aware of. I'm using a bare-bones LSP client that just invoked rust-analyzer without any arguments, initializationOptions, or workspace configuration.

In the communication log between my client and the server, I find this excerpt:

   (:jsonrpc "2.0" :id 216 :method "textDocument/inlayHint" :params
             (:textDocument
              (:uri "file:///home/capitaomorte/Source/Rust/bevy/crates/bevy_animation/src/lib.rs")
              :range
              (:start
               (:line 187 :character 0)
               :end
               (:line 238 :character 31))))
   [server-reply] (id:216) Mon Feb 27 14:11:25 2023:
   (:jsonrpc "2.0" :id 216 :result
             [(:position
               (:line 294 :character 1)
               :label
               [(:value "fn animation_player" :location
                        (:uri "file:///home/capitaomorte/Source/Rust/bevy/crates/bevy_animation/src/lib.rs" :range
                              (:start
                               (:line 185 :character 7)
                               :end
                               (:line 185 :character 23))))]

As you can see, this is requesting inlay hints for a specific region of the document and getting back hints for things outside this region. Easy enough to filter on my side, but I thought I'd report this here.

This was originally reported in Emacs's bug tracker: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61812

@joaotavora joaotavora added the C-bug Category: bug label Feb 27, 2023
@Veykril
Copy link
Member

Veykril commented Feb 27, 2023

The range restricts the calculation of inlay hints to a subset of the AST, which maybe larger than the passed in range here

if let Some(scope) = sema.scope(file) {
let famous_defs = FamousDefs(&sema, scope.krate());
let hints = |node| hints(&mut acc, &famous_defs, config, file_id, node);
match range_limit {
Some(range) => match file.covering_element(range) {
NodeOrToken::Token(_) => return acc,
NodeOrToken::Node(n) => n
.descendants()
.filter(|descendant| range.intersect(descendant.text_range()).is_some())
.for_each(hints),
},
None => file.descendants().for_each(hints),
};
}

We should filter out inlay hints that lie outside the range from the results.

@Veykril Veykril added the A-inlay-hints inlay/inline hints label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inlay-hints inlay/inline hints C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants