About me

The article start | my blog | welcome the attention

The introduction

When VsCode is used for Go program development, we will certainly encounter some problems. Some of these problems are IDE configuration problems, and some are inconsistent versions of downloaded packages. This article mainly focuses on the problems encountered in the development process to do a simple review and collation.

Preparation, must see

Before correcting the problem, make sure you have downloaded golang’s official toolset, Go-Tool, correctly. If you are not sure, just follow my steps. Maybe your problem will be solved.

1. Configure the golang source.

go env -w GOPROXY=https://goproxy.cn,direct
Copy the code

Then we go to the default tools service download for the Golang tool:

2. If you press Ctrl+Shift+P on Windows or Command+Shift+P on Mac, the VS Code screen will display an input box

3, we enter the input box >go:install, the following will automatically search for related commands, we select go:install /Update Tools command, click the following figure to select and press enter to execute the command

Select all in the window that pops up, and click the “OK” button to install.

Wait for the installation to complete, because of the particularity of the domestic network, so must know the go agent source, otherwise always download failure.

After this step, restart Vscode. If this time solves your problem, you don’t need to look further.

Specific problem solutions

If the above steps don’t solve your problem, it’s time to set it up for your own problem.

F12 cannot jump in VSCode

General Settings

Click the gear in the lower left corner and select the Settings screen (or press CTRL+ and click User-Extension-Go). Set it up as follows

1. Change DocsTool to godoc

2. Deselect Use Language Server

3. Restart VsCode

Go mod mode

If that still doesn’t work, and you’re using the Go mod, there’s a special way to solve the problem.

Run the go mod vendor command to 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 the code.

Two, the automatic code out function is invalid

This problem is usually caused by the go mod mode switch. If your project is using the Gopath mode (for those of you who are not familiar with Gopath and Gomod modes, see my article on How to look at Go Moudle and apply it to your work), do you need to set it up

go env -w GO111MODULE=off
Copy the code

At this point the automatic bring out function is likely to be used correctly

If you are using go Mod mode, set

go env -w GO111MODULE=on
Copy the code

The automatic bring out function can also be restored to normal.

This article refer to

Go Module Basic usage

Vscode Go did not find any definitions

Recommended reading

A new open source has emerged after the Redis tool is charged

GitHub Star’s top engineer Skills map

Chinese programmers are most likely to mispronounce words

Recommended!!!!!! The Markdown icon indexes the site

The last

The end of this article, hope to help you 😃

If there are any questions or suggestions, you can communicate more, original article, writing style is limited, talent is shallow, if there is something wrong in the article, hope to inform.

More wonderful technical articles in my public number [programmer toolset]], continue to update, welcome to pay attention to subscription collection.