How to turn off the automatic removal of unreferenced packages when saving Go language files in VS Code

When using Visual Studio Code to write Go language (Golang) program code, sometimes the quoted package is clearly quoted correctly, but it is automatically deleted when it is saved, which is mistaken for being unquoted. At this time, refer to the following steps to solve it.

 

Search for goimports in the Settings of Preference in VS Code, and you will see "Go: Format Tool". Just replace the goreturns or goimports used with gofmt.

 

Because goreturns or goimports will automatically do automatic package import or remove unreferenced packages. Of course, after this setting, packages that are used but not imported (import) must remember to manually ensure that they are imported. Convenience cannot have both.

Guess you like

Origin blog.csdn.net/weixin_41462458/article/details/107854207