rust-lang / rust-lang/rust-analyzer
Automatically save file when applying refactoring like "Insert mod" which modifies file without editor focus
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
This may be specific to the vscode extension.
Currently, if you apply a refactoring like Insert 'mod foo;', RA will modify the other file in-memory but not save it -- i.e., it leaves the parent module file dirty in your editor. It isn't obvious that this is the case unless you've learned the behavior via trial-and-error.
I routinely get bitten by this behavior when I'm not paying close attention: I create a new file, apply the "insert mod" rule, and then continue working. Some RA analysis works, even without saving the file. Presumably these are the ones it doesn't need to shell out to the real compiler for. Meanwhile, most error diagnostics aren't shown, and command-line tools will ignore the file since it isn't in the module tree. Until you scroll your tab list to discover the dirty editor, there isn't any indication you're in this intermediate state.
Many refactorings, such as renames, save automatically. And it's VSCode's default behavior to save files involved in a refactoring:

I think it would be apt to apply this to RA, or at least make it an option. Right now, the "insert mod" assist isn't very helpful, because I have to know to "save all" (if appropriate) or otherwise manually open the file and save it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue identifies the VS Code extension and the Insert 'mod foo;' refactoring as the entry point, but names no files or tests. Reproduce the assist with a new module file and inspect how refactoring changes are saved; done means the affected parent file is saved automatically or the behavior is exposed as an option.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100