rust-lang / rust-enhanced

The official Sublime Text 4 package for the Rust Programming Language
MIT License
780 stars 104 forks source link

Prevent editing of cargo-private registry files #469

Closed kornelski closed 2 years ago

kornelski commented 3 years ago

Sublime Text Version

4133

Rust Enhanced Version

2.24.0

Operating system

macOS Big Sur

Expected behavior

Users are not supposed to edit Rust source files inside CARGO_HOME (~/.cargo/registry), since these are meant to be immutable snapshots of crates. These files are treated as disposable, so users editing them by accident can lose their work.

Rust-analyzer's "jump to definition" function will happily jump to these files. This makes it easy to accidentally open a file of a dependency. Jumping to view these files is not bad per-se, but editing them by accident is problematic.

Actual behavior

Could you open Cargo registry files in read-only mode? Or show some kind of warning that the file is not supposed to be edited?

Steps to reproduce

  1. subl ~/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.99/src/lib.rs

References

ehuss commented 3 years ago

I'm not too familiar with the LSP plugin, but I think that would be responsible for setting the view read-only.

This plugin does this already (see here). When using the build system, if there is a diagnostic that points to something outside of the workspace, the view is opened read-only.

kornelski commented 3 years ago

I initially filed the request with rust-analyzer, but LSP can't do it, which is why they sent me here :)

ehuss commented 2 years ago

I'm going to close as I don't think there is anything this extension can do. The LSP extension is a separate project. I suspect it wouldn't be possible for it to know whether or not the file should be read-only (unless that is part of the LSP protocol).

We are looking to make the src cache read-only over at https://github.com/rust-lang/cargo/issues/9455, though we ran into some problems which will need some more work.

I realize this is an annoying issue, and trips up people quite a bit. Hopefully progress can be made on the cargo side.