Prevent editing of registry files from VSCode?

Yesterday I was perplexed when my build started breaking, because it couldn't build one of my dependencies. I eventually traced the problem to the fact that the files in my ~/.carg/reigistry/src directory had been modified, and were now not compiling. I fixed it by deleting those files and letting cargo redownload them.

I'm pretty sure what happened is this:

  1. I opened my project in VSCode
  2. I used the 'Go To Definition' action on one of the dependencies definitions
  3. VSCode opened the source file of my dependency in the ~/.cargo/registry/src tree
  4. I accidentally hit some keystrokes while that window was active
  5. VSCode auto-saves the file to ~/.cargo/registry/src

It is nice, sometimes, to be able to see the exact code of my dependencies. But I can't imagine there being any good reason to edit those files directly--at least, not without specific intent. But try as I might, I can't find any way to prevent VSCode from opening those files as editable by default. (I assume, as well, that trying to make my entire cargo registry read-only would cause other problems).

Is there something I'm missing? Does anyone have a way to configure VSCode to prevent this mistake from happening? Or do you just have to be careful?

1 Like

I've done this too, in particular I edited one of my own libraries, when using 'goto definition', on an extern project not of the same workspace which depended upon it.

It would be real nice if we could just open registry sources read-only, this is issue #5847,
It appears that nothing is blocking it anymore, just needs someone to implement it I believe.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.