Stream: t-compiler/rust-analyzer

Topic: File watching and Cargo.toml vs project.json


woody77 (Mar 10 2021 at 20:00, on Zulip):

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?)

Jonas Schievink [he/him] (Mar 10 2021 at 20:06, on Zulip):

I believe we are effectively using the IDE as a file watcher for Cargo.toml, at least with the default config

Jonas Schievink [he/him] (Mar 10 2021 at 20:07, on Zulip):

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

woody77 (Mar 10 2021 at 20:07, on Zulip):

Is that setup in switch_workspace?

woody77 (Mar 10 2021 at 20:09, on Zulip):

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)

Jonas Schievink [he/him] (Mar 10 2021 at 20:32, on Zulip):

woody77 said:

Is that setup in switch_workspace?

Yes, looks like it

Jonas Schievink [he/him] (Mar 10 2021 at 20:32, on Zulip):

At least it decides whether to use the client's functionality or the builtin watcher

Florian Diebold (Mar 10 2021 at 21:17, on Zulip):

I think we currently only listen to didSave for Cargo.toml, which is a problem

Jonas Schievink [he/him] (Mar 10 2021 at 21:18, on Zulip):

hmm, yeah

Jeremy Kolb (Mar 10 2021 at 21:25, on Zulip):

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

woody77 (Mar 10 2021 at 22:07, on Zulip):

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...)

woody77 (Mar 10 2021 at 22:08, on Zulip):

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?

Florian Diebold (Mar 10 2021 at 22:10, on Zulip):

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)

Jonas Schievink [he/him] (Mar 10 2021 at 22:10, on Zulip):

For didSave, you have to save the file with the editor, not outside

woody77 (Mar 10 2021 at 22:12, on Zulip):

Ok, that makes sense. And the VFS isn't used to watch files if VSCode is the watcher, correct?

Jeremy Kolb (Mar 10 2021 at 23:10, on Zulip):

Right. I think there's a setting for it... or there was a long time ago...

woody77 (Mar 11 2021 at 22:52, on Zulip):

There are still settings around that, yes.

woody77 (Mar 11 2021 at 23:24, on Zulip):

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.

Last update: Jul 24 2021 at 19:15UTC