Skip to content

Rust-analyzer inserts & (ampersand) character on the wrong line when auto-completing variable reference #12717

@stevepryde

Description

@stevepryde

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:

  1. Locate the line of code at the bottom (query_result(...))
  2. Above that line, type the following, but auto-complete the variable name
    show_value(request.que (then press ENTER to auto-complete query_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

Labels

A-completionautocompletionC-bugCategory: bugE-has-instructionsIssue has some instructions and pointers to code to get started

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions