-
Notifications
You must be signed in to change notification settings - Fork 795
Please, more reasonable defaults #3730
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
Comments
I have disabled everything that says it modifies the file on save but it still does it. |
Hi mythemeria, Thank you for reporting this issue. The go extension have some default behavior of formatting on save. Please see the FAQ here. If you follow instructions mentioned in this doc, you should be able to disable the format on save behavior (looks like the I'm not aware of any other default behavior other than this (probably because that is the only thing I have noticed). There is a problem reported earlier regarding this I'm not sure what kind of text edits are you observing, if this is still happening, we might need to work on a reproduce and try to resolve your issue. (Like share the step by step instructions so I can reproduce it from our end, and dive in detail of the LSP communication). Sorry for the confusion. |
Here is an example of the code changes. I have this snippet taken from an example I found online: package db
import (
"database/sql"
"github.com/lib/pq"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/source/file"
)
func Migrate() {
db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
driver, err := postgres.WithInstance(db, &postgres.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file:///migrations",
"postgres", driver)
m.Up() // or m.Steps(2) if you want to explicitly set the number of migrations to run
} When I save, it changes to this: package db
import (
"database/sql"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
)
func Migrate() {
db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
driver, err := postgres.WithInstance(db, &postgres.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file:///migrations",
"postgres", driver)
m.Up() // or m.Steps(2) if you want to explicitly set the number of migrations to run
} These were the same packages that were being removed before but now they're being removed because the packages are unused, not because I am missing them. I disabled the extension so I could save and restart vscode, which fixed the missing package error as expected. But anyway, adding this to my json settings fixed it, thanks. I had already modified the formatOnSave part. "editor.codeActionsOnSave": {
"source.organizeImports": "never"
} Keeping this issue open because I still think this can be made way less annoying. |
@mythemeria What specific change are you asking for? Changing the default value of
I suggest trying
What do you expect to happen? Do you not want unused imports to automatically be removed? Or is your issue specifically with packages that have not yet been added to Side note, if you use the code action to install missing packages, gopls will recognize that they've been installed without needing to restart it (or vscode). |
It only gave me an error saying that the package was not installed, which I fixed with the quick action like you mention. No mention of the unused package error until I disabled the extension and restarted, so I assumed that the missing package was the reason it was removed.
I am not sure what the best solution would be to appease everyone since I haven't exactly gone and asked other users what they expect it to do. I personally expect the save button to actually save my work, not change it and then save. Perhaps match the vscode settings by default? For sure it should be made easier to find how to disable this behaviour.
Neat, I will use that in future
I expect the save button the function the way every other save button works |
An unused import is always an error in Go, that's part of the language itself and the import organizer is designed partially to make it easier to comply with that. If an import is referenced and the organizer removes it, that is a bug. Whether the package is missing should not have any effect on that.
It sounds like you want to disable any on-save functionality (such as format-on-save). It is confusing that you have to disable both |
Is your feature request related to a problem? Please describe.
Yes. I keep finding that it edits my file before I save. Normally this is just mildly annoying but if there's any bugs in the linter then I can't save and re-open vscode to fix the issue. I frequently have issues (not just in go) where I try to install a new package but I still get errors saying the package is missing. Simply restarting vscode almost always fixes this. Not in go, because I can't save it without it removing the "missing" packages. I have spent the last 20 minutes trying to work out where to disable this without accidentally messing up all the settings but it's not clear at all. The descriptions don't give me enough information to work out which setting does what I want as it doesn't clearly tell me which ones are me saying "yes, I want you to edit my code when I save".
Describe the solution you'd like
Change the default behaviour so that it doesn't impede basic problem solving like restarting the program, or at least make it clearer how I can turn this off.
Describe alternatives you've considered
I guess I will be spending reading all the docs to work out how to fix this, but it is still incredibly annoying that it will remove my code that is there for a reason. It's a bit unreasonable to expect people to only save when the code is perfect.
The text was updated successfully, but these errors were encountered: