Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VS Code not auto-import packages using Go?

Hi I am new to Go and currently use VS Code as IDE.

I am totally new to back-end development and I am trying to use Go for the job.

While I was teaching myself via Youtube, I faced a problem.

The problem is that the VS Code does not auto-import any package made by me.

I don't know why but I did get some clues about it.

My Guess

  • My editor does not recognize the location of the package

also my projects are located at C:\Users\John\Desktop\GoProjects while the gopath=C:\Users\John\go and the goroot=c:\go

Can anyone give me a solution to this?

main.go myapp/app.go

like image 425
Johntopia Avatar asked Nov 21 '25 10:11

Johntopia


1 Answers

In my case disabling gopls worked and easily solved the issue.

File -> Preferences -> Settings -> Use Language Server (Type in search box and uncheck it)

Read the complete thread here for detailed information : https://github.com/microsoft/vscode-go/issues/2473

You can also import missing libraries using Command Palette (Cntrl + Shift + P) which is also very simple.

Open the Command Palette and run the command Go: Add Import to get a list of packages that can be imported to your Go file. Choose one and it will get added in the import block of your Go file.

like image 130
Muhammad Tariq Avatar answered Nov 24 '25 03:11

Muhammad Tariq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!