about me
Article first | My blog | Welcome to follow
introduction
Using VsCode for Go program development, we will definitely encounter some problems. Some of these problems are IDE configuration problems, and some are download package version inconsistencies. This article mainly focuses on the problems encountered in the development process to do a simple review and sort out.
Preliminary preparation, must see
Before correcting the problem, make sure that you have downloaded the official golang toolset correctly go-tool
. If you are not sure, just follow my steps. After the operation, your problem will be solved.
1. Configure the source of golang.
go env -w GOPROXY=https://goproxy.cn,direct
Then we download the default tool service of the golang tool:
2. Press on Windows platform and press Ctrl+Shift+P
on Mac platform Command+Shift+P
. At this time, an input box will pop up on the VS Code interface
3. We enter in this input box >go:install
, the following will automatically search for related commands, we select Go:Install/Update Tools
this command, select it as shown in the figure below and press Enter to execute the command
Select all in the pop-up window and click the "OK" button to install.
Wait for the installation to complete. Because of the particularity of the domestic network, you must know the proxy source of go, otherwise the download will always fail.
After performing this step, restart Vscode. If your problem can be solved at this time, you don't need to read further.
Solutions to specific problems
If the above steps cannot solve your problem, then you can set the operation according to your own problem.
1. F12 cannot jump in VSCode
General settings
Click the gear in the lower left corner and select the settings interface (you can also directly CTRL+,
click the shortcut key to click user-extend-go. Make the following settings
1. Modify DocsTool to godoc
2. Uncheck Use Language Server
3. Restart VsCode
go mod mode
If the above operations still do not work, and you are using go mod mode, there is a special way to solve this problem.
Execute the command to go mod vendor
import the dependencies, this step will transfer the dependencies to the vendor (automatically created) folder in the root directory of the project
At this point, F12 can jump to the code.
Second, the code automatically brings out the function is invalid
This problem usually because of go mod
switching mode caused. If your project uses the Gopath mode (if some students don’t understand the two modes of Gopath and Gomod, you can read my article on how to treat go moudle and apply it to work ), then you need to set
go env -w GO111MODULE=off
At this time, the automatic bring-out function may be used correctly
If you are using go mod
mode, set
go env -w GO111MODULE=on
The automatic bring-out function can also be restored to normal.
Article reference
vscode go did not find any definitions
Recommended reading
New open source has emerged after Redis tool charges
Star's highest engineer skill map on GitHub
The most prone word for Chinese programmers to send wrong words
Recommend!!! Markdown icon index website
At last
This concludes this article, I hope it helps you