-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add setting to save modified files after applying a refactoring #2433
Add setting to save modified files after applying a refactoring #2433
Conversation
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@jwortmann thank you! Let's jump in the feedback. So I did a little research with how VS Code behaves. I know that customization is good to have. VS Code does keep it simple regarding the logic for renaming. Here is how VS Code behaves when renaming symbols. Let's say we have two files:
CASE 1If we have
CASE 2If we have
CASE 3If we have to illustrate... _|_foo.ts_| bar.ts* |_____
import { foo } from '.foo'
+ // this was added, and we didn't save If we go back to the
In VS code will end up with both files being saved.
In all 3 cases, VS Code behaves the same. I think that LSP for ST could behave the same, There are of course downsides. Luckily now, we do show a popup to that says "Rename 55 occurrences in 60 files.", so we are safe in some way... and we have a preview edits that you have improved in your last PR. So I think we kind guards against this... Also LS can prevent this in textDocument/prepareRename to throw "You can not rename this element" All in all, to sum up: WDYT? |
If we implement as VS Code here would be the answers:
We will save all files that have workspace edits, and don't care if the file had modifications or not.
Yes, we would open, save and close the files that were not already open in the window.
We would save the file, regardless if it had unsaved changes.
We would only have one default behavior and no options....
1+ Maybe open files that are not part of the workspace? I would like no additional logic... but I do not know what is sane here.
If we implement as VS Code, we would not need such option.
If we implement as VS Code, I do not think we would need a new setting. |
Thanks for the feedback and testing how it works in VS Code! So the only difference is case 3, where VS Code saves even the files with previously unsaved changes. I must say that from my point of view the behavior I implemented here is better and what I would expect as a user. If I had an unsaved file open, then I don't want the editor to save it by its own when I do a rename operation. For example sometimes I intentionally leave files with some experimental or temporary changes unsaved, so I can simply close the file (without saving) and reopen it, if it turns out that the changes were wrong and I'd like to revert them.
Well, it depends on what exactly is meant with "behaves the same". VS Code behaves the same in the way that it always saves all files. But this implementation behaves the same in all 3 cases in the way that the original file state is always preserved. So both are consistent in their own way 😉
Hm... I could imagine that some users wouldn't like the new behavior, especially that unopened files are immediately closed again. So I would expect some complaints if this will be forced upon all users.
Interesting idea. But I think in general there should never be files affected by a WorkspaceEdit (name speaks for itself) that are outside of the workspace. I would think that the case you experienced where |
I noticed that VS Code has this setting: // Controls if files that were part of a refactoring are saved automatically
"files.refactoring.autoSave": true, If set to Something else I noticed is that with this PR, unopened files will be visible in the tab bar for a very short amount of time, before they are immediately closed again. I assume this happens because |
+1 for the behavior of VS Code (even as new default). It happens quite often that I miss to save all other tabs. |
Then I would probably add a new setting, but with multiple options: // Controls if files that were part of a refactoring are saved automatically:
// "always" - save all affected files
// "preserve" - only save files that didn't have any unsaved changes beforehand
// "preserve_opened" - only save files that didn't have any unsaved changes beforehand
// and were already open in the editor
// "never" - never save files automatically
"refactoring_auto_save": "never", This would apply to all workspace edits, i.e. also to code actions and to manually triggered commands. So if you choose "always", it means that your file is saved automatically after applying a code action, even if it only affects the active file. Perhaps we should pass the code action kind further to the function and only save if the kind is "refactor" (I think this is what VS Code does). |
This fixes for example the Pyright warning LSP-pyright: Received change text document command for closed file <URI> when a file is saved and closed immediately after changes were applied.
This fixes for example the Pyright warning LSP-pyright: Received change text document command for closed file <URI> when a file is saved and closed immediately after changes were applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ✅
Thanks, |
Closes #2371
Edit: the following info is outdated, see #2433 (comment) for the updated version of this PR.
This would allow to add a key binding for the rename command like
and with this new
"preserve_tabs"
argument enabled, after applying the edits it will automaticallyQuestions: