Home>Article>Backend Development> Sort out the problems that occur with go encoding in vscode

Sort out the problems that occur with go encoding in vscode

藏色散人
藏色散人 forward
2021-03-17 17:06:26 2530browse

The following tutorial column will sort out the problems that occur in go encoding in vscode. I hope it will be helpful to friends in need!

Sort out the problems that occur with go encoding in vscodeIntroduction

When using VsCode to develop Go programs, we will definitely encounter some problems, some of which are related to the configuration of the IDE Some of the problems are inconsistent versions of the downloaded packages. This article mainly provides a simple review and organization of the problems encountered during the development process.

Preliminary preparation, must read

Before correcting the problem, make sure you have correctly downloaded golang’s official tool setgo-tool, if you are not sure, just 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. Press on Windows platform

Ctrl Shift P

, press

Command Shift P

on Mac platform. At this time, an input box will pop up in the VS Code interface

3. We enter

>go:installSort out the problems that occur with go encoding in vscodein this input box. The following will automatically search for related commands. We select the command

Go:Install/Update Tools

. Select it as shown below and it will return Car execute this commandSelect all in the pop-up window and click the "OK" button to install.

# Wait for the installation to be completed. Because of the particularity of the domestic network, someone must know the proxy source of go, otherwise the download will always fail.

Sort out the problems that occur with go encoding in vscodeAfter executing this step, restart Vscode. If your problem can be solved at this time, there is no need to read further.

Specific problem solutions

If the above steps cannot solve your problem, you can perform operation settings corresponding to your own problems.

1. F12 cannot jump in VSCode

General Settings

Click the gear in the lower left corner and select Setting interface (you can also directly use the shortcut keyCTRL,and click User-Extension-go. Make the following settings

1. Modify DocsTool to godoc

2. Uncheck Use Language Server

Sort out the problems that occur with go encoding in vscode

3. Restart VsCode

Sort out the problems that occur with go encoding in vscode

go mod mode

If it still doesn’t work after the above operations, and you are using go mod mode, there is a special way to solve this problem.Execute the command

go mod vendor

Import dependencies , this step will transfer the dependencies to the vendor (automatically created) folder in the root directory of the project

At this time, F12 can jump to the code.

2. The code automatic bring-out function fails

This problem is generally caused by the switch ofgo modmode. If your project uses Gopath mode (if any students are interested in Gopath If you don’t understand the two modes of Gomod, you can read my article

How to treat go moudle and apply it to work

), then you need to setgo env -w GO111MODULE=offAt this time, the automatic bring-out function may be used correctly

If you are using the

go mod

mode, set

go env -w GO111MODULE= onThe automatic bring-out function can also be restored to normal.

The above is the detailed content of Sort out the problems that occur with go encoding in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete