Skip to content
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

Aggressive Autosaving Causes File Reformat #133

Closed
Kryan90 opened this issue Aug 11, 2023 · 6 comments · Fixed by #136
Closed

Aggressive Autosaving Causes File Reformat #133

Kryan90 opened this issue Aug 11, 2023 · 6 comments · Fixed by #136
Assignees

Comments

@Kryan90
Copy link

Kryan90 commented Aug 11, 2023

This plugin causes auto-save to trigger immediately after I stop typing when a proto file is open but not in focus

Example:
Have a .go file open, open a .proto file -> split and move right
Add a new line to the .go file, auto-save is triggered and go fmt runs removing the newline

Similar to this issue, but I confirmed it is specifically the buf plugin causing it for me: https://youtrack.jetbrains.com/issue/WEB-54949/auto-save-as-soon-as-stop-typing

@Kryan90
Copy link
Author

Kryan90 commented Aug 11, 2023

Unchecking these two settings seems to fix the undesired behavior
image

@bufdev
Copy link
Member

bufdev commented Aug 11, 2023

We'll check this out, thanks for the bug report.

@pkwarren pkwarren self-assigned this Aug 15, 2023
@pkwarren
Copy link
Member

@Kryan90 - I'm not able to reproduce the issue with the steps above. Only when making a change to the open .proto file do I see that all files are auto saved, which triggers the 'Tools -> Actions on Save -> Reformat code' action to run 'go fmt' on the .go files.

Can you provide more details on the version of IntelliJ/GoLand you are using, the Buf plugin version, and anything else that might allow me to reproduce the problem on my end?

@Kryan90
Copy link
Author

Kryan90 commented Aug 16, 2023

buf plugin: 0.1.5
GoLand 2023.2 - Build #GO-232.8660.185, built on July 25, 202

It seems to happen within specific contexts, for example inside a function body or struct definition. I took a short video to demonstrate the behavior

Screen.Recording.2023-08-16.at.11.17.22.AM.mov

@pkwarren
Copy link
Member

@Kryan90 - Thanks for the additional context. I'm able to reproduce the behavior here, but even after some fixes to the plugin to reduce the saved documents to only .proto files, it appears that as part of running a background task there is another location in IntelliJ which triggers a save of all unsaved documents: https://github.com/JetBrains/intellij-community/blob/66b0623ced948ee43cb22e32ecaee1c791b22c1f/platform/configuration-store-impl/src/SaveAndSyncHandlerImpl.kt#L179-L180

Any save triggers the default 'Reformat code' action in Tools -> Actions on Save, which leads to the reformatting.

I'll continue to try and find a fix for this issue, however it may be more complex than I initially thought.

pkwarren added a commit that referenced this issue Aug 17, 2023
Currently, any editor with a .proto file open will trigger reformatting
(even if the .proto file itself isn't changed). This appears to be
related to changes in editor focus when background jobs are run.

Update the plugin to keep track of a modification count based on the
protobuf files in the project in addition to the Buf CLI configuration
and plugin configuration. Only run 'buf breaking' and 'buf lint' if the
count changes (since changes to non-proto/buf files won't impact the
results).

This should greatly reduce the times we run background jobs and avoid
unnecessary reformatting of non-proto files during editor sessions.

Fixes #133.
pkwarren added a commit that referenced this issue Aug 18, 2023
Currently, any editor with a .proto file open will trigger reformatting
(even if the .proto file itself isn't changed). This appears to be
related to changes in editor focus when background jobs are run.

Update the plugin to keep track of a modification count based on the
protobuf files in the project in addition to the Buf CLI configuration
and plugin configuration. Only run 'buf breaking' and 'buf lint' if the
count changes (since changes to non-proto/buf files won't impact the
results).

This should greatly reduce the times we run background jobs and avoid
unnecessary reformatting of non-proto files during editor sessions.

Fixes #133.
@pkwarren
Copy link
Member

@Kryan90 - The behavior should be much improved in version 0.2.1 (available now). There are some cases where you may still see auto-save trigger reformatting of Go code, but it should be much less frequent than before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants