Using vscode for go program development, we will certainly encounter some problems, some of which are ide configuration problems, some of which are inconsistent versions of download packages. This paper mainly reviews and sorts out the problems encountered in the development process.
Preparation, must see
Before correcting the problem, make sure you download the official tool set of golang correctly
go-toolIf you’re not sure, follow my steps. Maybe 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 golang tool
2. Windows platform press
Ctrl+Shift+P, Mac platform press
Command+Shift+PAt this time, an input box will pop up in the vs code interface
3. Let’s type in this input box
>go:install, the following will automatically search for related commands, we choose
Go:Install/Update ToolsThis command is selected according to the figure below and will be executed by carriage return
Select all in the pop-up window and click “OK” to install.
Waiting for the installation to be completed, because of the particularity of the domestic network, we must know the proxy source of go, otherwise the download always fails.
After performing this step, restart vscade. If your problem can be solved at this time, you don’t need to look further.
Solutions to specific problems
If the above steps can’t solve your problem, you can set the operation according to your own problem.
1、 F12 in vscode cannot jump
Click the gear in the lower left corner to select the setting interface (or directly press the shortcut key)
CTRL+,Click user – extend – go. Make the following settings
1. Modify docstool to godoc
2. Use language server remove check
3. Restart vscode
Go mod mode
If you still can’t do the above operation, and you use go mod mode, there is a special way to solve this problem.
Execute the order
go mod vendorImport the dependency. This step will transfer the dependency to the vendor folder in the root directory of the project
At this point, F12 can jump the code.
2、 Code auto bring out function failure
This problem is generally due to
go modMode switching. If you use gopath mode in your project (if you don’t know about gopath and gomod, please see my article)How to view 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 modMode, setting
go env -w GO111MODULE=on
The automatic take out function can also return to normal.
The end of this article, I hope to help you
If you have any questions or suggestions, you can exchange more, original articles, writing is limited, talent and learning is shallow, if there are any mistakes in the article, please let me know.
More exciting technical articles are summarized in my official account toolkit, and I want to continue to update.