I found an unavoidable error when writing Rust code. This is caused by the fact that the rust-analyzer extension of VS Code (or other editors) cannot automatically run in the nix-shell environment.
Currently, apart from executing nix-shell in the terminal, and then entering code to start, so that the VS Code process inherits this environment, I have no way to avoid its errors.
I submitted a related feature request to the rust-analyzer project (issue here), but the possibility of support may be low. Because this is more like an editor or system defect.
I don’t know if you have a better way to solve this problem.
Personally, in Emacs I solve this using direnv integration, which will load the environment that I’m expecting when I visit certain project directories: