I've noticed that when using Cargo.toml projects, adding new dependencies to crates seems to be picked up immediately, as if the Cargo.toml files are being watched (or if the LSP / extension is seeing the edits and acting accordingly).
It appears that editing the Cargo.toml files causes a reload of the whole workspace. But I know that project.json files aren't similarly reloaded. (otoh, the ~600 crates that the
rust-analyzer workspace contains doesn't take long to process vs. the ~3000 that I have in my project.json).
Is the Cargo.toml reprocessing done through watching on the filesystem, or via the IDE (and is that what the "client" watcher is, the IDE?)
I believe we are effectively using the IDE as a file watcher for Cargo.toml, at least with the default config
You can also tell r-a to use a native file watching implementation, but I'm not sure if Cargo.toml works with that setting
Is that setup in
I'm torn on whether I want it to watch my
project.json, but it would probably be a usability improvement. (when adding new crates/deps I end up telling r-a to reload the workspace a bunch)
Is that setup in
Yes, looks like it
At least it decides whether to use the client's functionality or the builtin watcher
I think we currently only listen to
didSave for Cargo.toml, which is a problem
Yeah it's just
didSave for the moment: https://github.com/rust-analyzer/rust-analyzer/blob/16a76aa158d0898d6a46d7bba7310150555a69b9/crates/rust-analyzer/src/main_loop.rs#L123-L131
Oh, interesting.... And since project.json is (I assume) usually generated, not edited (at least it is for us), then adding "project.json" to that list wouldn't really work (although it would allow for hand-edits...)
Although, would VSCode tell the LSP that the file changed because VSCode's own file-watcher detected a change? or would it need to be open in an editor for that to happen?
didSave only happens if you actually edit it in the editor. that's the problem. There is a separate mechanism with which we can register file watchers, but we don't use it for Cargo.toml yet (I think because it's not completely trivial because we'd have to add it to the VFS)
didSave, you have to save the file with the editor, not outside
Ok, that makes sense. And the VFS isn't used to watch files if VSCode is the watcher, correct?
Right. I think there's a setting for it... or there was a long time ago...
There are still settings around that, yes.
So in general, it sounds like for
project.json, we don't have any short paths to more automatic support than to reload the extension... And from looking at things, by the time we're setting up file watching, we've elided the source of the workspace(s) / a crate graph, divorced from the Cargo.toml or project.json that created it.