Sorting out the problems of go coding in vscode

Time:2021-6-5

introduction

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 correctlygo-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 pressCtrl+Shift+P, Mac platform pressCommand+Shift+PAt this time, an input box will pop up in the vs code interface

Sorting out the problems of go coding in vscode

3. Let’s type in this input box>go:install, the following will automatically search for related commands, we chooseGo: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.

Sorting out the problems of go coding in vscode

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

General settings

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

Sorting out the problems of go coding in vscode

2. Use language server remove check

Sorting out the problems of go coding in vscode

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 ordergo 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 togo 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 usinggo modMode, setting

go env -w GO111MODULE=on

The automatic take out function can also return to normal.

Article reference

Basic use of go module

Vscode go did not find any definitions

About me

My blog article starts

last

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.

Sorting out the problems of go coding in vscode