Closed
Description
When I auto-complete a function parameter that wants a reference, I get a &
character randomly inserted on the wrong line in the same file.
It appears to use the line-number relative to the file rather than relative to the current function.
See below for code and steps to reproduce the issue.
rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
rust-analyzer version: 0.0.0 (75b2232 2022-07-03)
rustc version: (eg. output of rustc -V
)
rustc 1.62.0 (a8314ef7d 2022-06-27)
#[derive(Debug)]
pub struct QueryResultRequest {
query_id: String,
}
pub async fn query_result(request: QueryResultRequest) -> Result<String, String> {
Ok(request.query_id)
}
pub fn show_value(value: &str) {
println!("value: {value}");
}
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test() {
let request = QueryResultRequest {
query_id: "test".to_string(),
};
query_result(request).await.unwrap();
}
}
Steps to reproduce:
- Locate the line of code at the bottom (
query_result(...)
) - Above that line, type the following, but auto-complete the variable name
show_value(request.que
(then press ENTER to auto-completequery_id
)
Upon auto-completion, observe an &
character has been inserted on line 6 of the file, making the function signature now look like this:
pub async fn query_result(request: QueryResultRe&quest) -> Result<String, String> {
^
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
stevepryde commentedon Jul 8, 2022
if I change
#[tokio::test]
to#[test]
and remove the async etc. I can't reproduce the issue. May be related to that macro, not sure.Veykril commentedon Jul 8, 2022
Ah we don't consider macros for these ye, these are all the problematic locations
rust-analyzer/crates/ide-completion/src/render.rs
Line 138 in 09abd76
rust-analyzer/crates/ide-completion/src/render.rs
Line 317 in 09abd76
rust-analyzer/crates/ide-completion/src/render/function.rs
Lines 82 to 92 in 09abd76
rust-analyzer/crates/ide-completion/src/render/literal.rs
Lines 124 to 126 in 09abd76
We'll need to use
rust-analyzer/crates/hir/src/semantics.rs
Lines 250 to 254 in 09abd76
abusch commentedon Jul 8, 2022
I can also reproduce this by typing
show_value(request.query_id);
(without using completion), then executing the "Add reference here" code action, so it doesn't seem to only concern completion.Veykril commentedon Jul 8, 2022
thats the same issue in a different part of the project, feel free to create a new issue regarding that
0xPoe commentedon Jul 16, 2022
I am working on this.
0xPoe commentedon Jul 16, 2022
@rustbot claim
Auto merge of #12800 - hi-rustin:rustin-patch-issue-12717, r=hi-rustin
Auto merge of #12830 - hi-rustin:rustin-patch-issue-12717-fix, r=Veykril
2 remaining items