rust-analyzer: Unable to locate source lines when Rust subproject folder is opened in VSCode
Minimal repro: rust_analyzer_workspace_bug.zip
The attached workspace has these files:
rust_analyzer_workspace_bug
├── .vscode
│ └── launch.json
├── Cargo.lock
├── Cargo.toml
└── subproject
├── .vscode
│ └── launch.json
├── Cargo.toml
└── src
└── main.rs
Quick Repro steps:
- Unzip the file
- Run
code rust_analyzer_workspace_bug/subproject. (This opens the project atsubfolderrather than at the root, in order to reproduce this issue.) - Hit F5 to build & run
- Verify a build error occurs in the Problems pane (due to a deliberate bug in
main.rs.) - Click the build error.
Observe: a tab opens with the message “The editor could not be opened because the file was not found.” Expected: the file to open with the cursor on the line containing the bug.
Note: this bug can be mitigated by adding the file subfolder/.cargo/config.toml, with the contents:
[build]
rustflags = ["--remap-path-prefix", "subproject/="]
However, this fixes the above problem, only to introduce an equally serious one: debugger symbols are incorrectly mapped, and breakpoints are not resolved correctly.
I haven’t found any way to have both of these work simultaneously:
- Build errors correctly displaying the correct file and line when clicked.
- Debugger symbols being correctly resolved during debugging.
So I’ve needed to comment out the lines in config.toml when debugging, and re-enable them when just compiling. This is tedious and frustrating and would really appreciate a fix asap.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (9 by maintainers)
A Critique of Pure NotMyProblemItis
A recurring theme in this issue is: “there’s nothing rust-analyzer can do, this is a vscode (or cargo) issue.” This is, sadly, plain wrong. There is much you can do, and ought to do. Net: your component has a bug - it is emitting incorrect paths. Nothing forces you to use paths computed by external crates. If you do, you need to take responsibility for bugs in those calculations and ensure that those bugs are fixed.
If VSCode (or cargo) was broken in a way that some fundamental rust-analyzer functionality was broken, for sure you would be on the case, investigating, filing bugs against vscode/cargo and pushing until a fix was made that restored rust-analyzer’s own functionality.
This issue falls into exactly the same category, except that you folks seem disinclined for whatever reason to do anything about it. Case in point, @davidbarsky lets slip that “rust-analyzer could fix this in the extension”, but stops responding when asked how.
Anyhow, this issue is a cross-boundary issue, and you own one half of the cross-component chain, and it’s your components’ behavior that is impacted. So it is really up to you to pursue the issue through to completion.
Instead, you throw your hands up and leave it up to a normal user, me, who has made considerable efforts to get this fix underway by providing clear steps to reproduce the issue, to figure out the innards of what might be going wrong in order to be the intermediary between the two teams? What an apathetic situation.
As they say, where there’s a will there’s a way. I know this post may lead to petulant refusal, but TBH it looks like we’re already there.
Closing this issue summarily in this half-investigated state is totally inappropriate.
I hope that some of the leads will take notice.