Search code examples
govisual-studio-code

Golang VSCode how can I stop/pause auto importing?


I'm finding the auto import active in Visual Studio Code for Golang is adding the incorrect package references automatically. Noticing that this has happened then going and correcting it all the time is a real pain.

To avoid this, and other annoying interfering handholding, is it possible to turn off auto importing or at least pause it for a while? Well keeping other nice features. I know I can just use a very simple text editor instead. (Basically tell the pushy pair programming partner to go and fetch a couple of coffees.)


Solution

  • Here's how you can disable auto imports in Visual Studio Code for the Go extension:

    1. Open the settings in Visual Studio Code by clicking on the gear icon in the bottom left corner or by pressing Ctrl + , (comma).

    2. In the search bar at the top of the settings window, type "go" to filter the settings related to the Go extension.

    3. Look for the setting called "Go: Add Tags" and uncheck the checkbox. This setting controls whether the Go extension should automatically add import statements when you use a new identifier in your code.

    4. Close the settings window.

    After disabling the "Go: Add Tags" setting, the Go extension should no longer automatically add import statements when you use new identifiers in your code. However, keep in mind that you won't get auto-import suggestions anymore, so you'll need to manually import the packages you need.

    NOTE: Do check the documentation and go version.