This is a creation in Article, where the information may have evolved or changed.
Vscode Golang Environment Configuration
After installing the Vscode, install the Golang plugin, you can use the Ctrl+shift+p or F1 call out command panel, enter extensions, enter the keyword go and then install
Then you pull a folder into Vscode, and then you do the workspace settings task through the preferences----and workspace settings. In the profile Settings.json of the workspace, we need to set the Go.gopath
{ "go.gopath": "${workspaceRoot}/../../../../", "go.buildOnSave": false}
After setting up the Gopath, our workspace settings are complete.
The Go plugin relies on many tools to complete code hinting, lint, and more. There are two options to download in the Vscode prompt, or to download the compiled binary package directly. In Git I have compiled a variety of dependency packages, it should be noted that only 64-bit environment in order to support delve debugging support, we unpack the compressed package, put into the Gopath/bin directory, so the dependent tool is ready.
- Shortcut key build and install
To quickly implement build and install, we use tasks here to accomplish this task. First, we call out the command panel, enter Tasks:configure task Runner, and then we enter the Tasks.json edit window, and we configure a build task in the following way, configured under the Tasks array:
{ "taskName": "vscgo_build", "isBuildCommand": true, "args": [ "${workspaceRoot}", "${fileDirname}" ], "isWatching": false, "problemMatcher": { "owner": "go", "fileLocation": [ "relative", "${fileDirname}" ], "pattern": { "regexp": "^(.*):(\\d+):\\s+(.*)$", "file":1, "line": 2, "message": 3 } }}
By setting Isbuildcommand, we can start the task quickly with Ctrl+shift+b shortcut, and Problemmatcher matches the error output with a regular, so that the wrong line is marked with a wavy red. Finally started is the Vscgo_build script, I have only written under the Windows processing, Linux slightly changed on the line:
@rem param1 GOPATH@rem param2 build path@SET GOPATH=%1@CD %2@go build@rem succeed or failed@if %errorlevel%==0 (echo build success) else (echo build failed)
And the install is similar, just can't call out through the shortcut key, only through the call Out command panel, input tasks:run task to choose Vsc_install to do. The configured task is as follows:
{ "taskName": "vscgo_install", "args": [ "${workspaceRoot}", "${fileDirname}" ], "isWatching": false, "problemMatcher": { "owner": "go", "fileLocation": [ "relative", "${fileDirname}" ], "pattern": { "regexp": "^(.*):(\\d+):\\s+(.*)$", "file":1, "line": 2, "message": 3 } } }
The script is as follows:
@rem param1 GOPATH@rem param2 build path@SET GOPATH=%1@CD %2@go install@rem succeed or failed@if %errorlevel%==0 (echo install success) else (echo install failed)
So our approximate configuration task is done, and these things are already packaged in Git.