rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.05k stars 1.56k forks source link

Opening a standalone .rs file after a .txt file makes rust-analyzer unresponsive. #17627

Open skr2005 opened 1 month ago

skr2005 commented 1 month ago

editor: vscode 1.91.1 with rust-analyzer on Windows

rust-analyzer version: 0.3.2037-standalone (e9afba57a 2024-07-14)

rustc version: 1.79.0 (129f3b996 2024-06-10)

relevant settings: default

To reproduce the problem, you can create a new folder containing a test.txt file including nothing, and a test.rs file including some simple code. Then, open them in order without opening the whole folder in vscode:

code test.txt
code test.rs

Now they are opened in the same vscode window. Wait for a while, and hover over some variables, the information will remain "Loading...". Other functions of rust-analyzer like code completion have no response as well. What's more, CPU usage of rust-analyzer.exe becomes very high. This situation continues until vscode is closed.

Young-Flash commented 1 month ago

seems stucked at scanning, and can not restart ([Error - 11:06:46 PM] Stopping server timed out)

[Trace - 11:08:32 PM] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "0/2: /home/flash/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort",
        "percentage": 0
    }
}

[Trace - 11:08:32 PM] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "0/2: /home/flash/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind",
        "percentage": 0
    }
}

[Trace - 11:08:32 PM] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "0/2: /home/flash/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/backtrace",
        "percentage": 0
    }
}

[Trace - 11:08:32 PM] Received notification '$/progress'.
Params: {
    "token": "rustAnalyzer/Roots Scanned",
    "value": {
        "kind": "report",
        "cancellable": false,
        "message": "0/2: /home/flash/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test",
        "percentage": 0
    }
}
alibektas commented 1 month ago

@Veykril it would be awesome if you could help me with writing a slow-test for this particular bug. I am not sure how I can reflect

To reproduce the problem, you can create a new folder containing a test.txt file including nothing, and a test.rs file including some simple code. Then, open them in order without opening the whole folder in vscode:

in my test case

#[test]
fn abc() {
    let dir = TestDir::new();
    let dir_path = dir.path().to_owned();

    let server = Project::with_fixture(
        r#"
//- /foo/Cargo.toml
[package]
name = "foo"
version = "0.0.0"

//- /foo/src/main.rs
pub main() {
    ()
}

//- /foo/test.txt

//- /foo/test.rs
fn other_func() -> i32 {
   3
}

fn main() {
   let abcdef = other_func();
   ()
}
"#,
    )
    .root("foo")
    .tmp_dir(dir)
    .server()
    .wait_until_workspace_is_loaded();

    //     server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
    //         text_document: TextDocumentItem {
    //             uri: Url::parse(dbg!(&format!("file://{}/foo/test.txt", dir_path))).unwrap(),
    //             language_id: "".to_owned(),
    //             version: 0,
    //             text: "".to_owned(),
    //         },
    //     });

    //     server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
    //         text_document: TextDocumentItem {
    //             uri: Url::parse(dbg!(&format!("file://{}/foo/test.rs", dir_path))).unwrap(),
    //             language_id: "".to_owned(),
    //             version: 0,
    //             text: r#"
    // fn other_func() -> i32 {
    //     3
    // }

    // fn main() {
    //     let i = other_func();
    //     ()
    // }                 "#
    //                 .to_owned(),
    //         },
    //     });

    let res = server.send_request::<HoverRequest>(HoverParams {
        text_document_position_params: TextDocumentPositionParams {
            text_document: TextDocumentIdentifier {
                uri: Url::parse(&format!("file://{}/foo/test.rs", dir_path)).unwrap(),
            },
            position: Position { line: 5, character: 10 },
        },
        work_done_progress_params: WorkDoneProgressParams { work_done_token: None },
    });

    dbg!(res);
}
Veykril commented 1 month ago

There are no cargo.tomls involved. This is an issue with the detached files infra, not sure if the test infra can model this right now. Have a look at the vscode extensions handling of detachedFiles