commit | f3dda9b4bc8339964f927a9583970d7786f14bc7 | [log] [tgz] |
---|---|---|
author | Ramya Achutha Rao <ramyar@microsoft.com> | Wed Mar 29 16:32:47 2017 -0700 |
committer | Ramya Achutha Rao <ramyar@microsoft.com> | Wed Mar 29 16:32:47 2017 -0700 |
tree | 0d4996678146d536047ddfae40d516d93c13fcd1 | |
parent | 2dc46414e2839c12133da82ec4becd3c4d5d42af [diff] |
telemetry updates
Important Note: If you have recently upgraded to Go 1.7 or Go 1.8, you may need to run gocode close
in your terminal and rebuild gocode
to ensure Go completion lists continue to work correctly. See https://github.com/Microsoft/vscode-go/issues/441.
Read the Release Notes to know what has changed over the last few versions of this extension
This extension adds rich language support for the Go language to VS Code, including:
gocode
)gogetdoc
or godef
+godoc
)gogetdoc
or godef
+godoc
)gogetdoc
or godef
+godoc
)guru
)go-outline
)go-symbols
)gorename
. Note: For Undo after rename to work in Windows you need to have diff
tool in your path)go build
and go test
)golint
or gometalinter
)goreturns
or goimports
or gofmt
)gotests
)gopkgs
)gomodifytags
)delve
)First, you will need to install Visual Studio Code. Then, in the command palette (cmd-shift-p
) select Install Extension
and choose Go
.
In a terminal window with the GOPATH environment variable set to the GOPATH you want to work on, launch code
. Open your GOPATH folder or any subfolder you want to work on, then open a .go
file to start editing. You should see Analysis Tools Missing
in the bottom right, clicking this will offer to install all of the Go tooling needed for the extension to support its full feature set. See the Tools section below for more details.
Note 1: Read GOPATH in the VS Code Go extension to learn about the different ways you can get the extension to set GOPATH.
Note 2: Users may want to consider turning Auto Save
on in Visual Studio Code ("files.autoSave": "afterDelay"
) when using this extension. Many of the Go tools work only on saved files, and error reporting will be more interactive with Auto Save
turned on. If you do turn Auto Save
on, you may also want to turn format-on-save off ("go.formatOnSave": false
), so that it is not triggered while typing.
Note 3: This extension uses gocode
to provide completion lists as you type. To provide fresh results, including against not-yet-built dependencies, the extension uses gocode
's autobuild=true
setting. If you experience any performance issues with autocomplete, you should try setting "go.gocodeAutoBuild": false
in your VS Code settings.
The following Visual Studio Code settings along with their default values that are available for the Go extension. If you want to change any of these, you can do so in user preferences (cmd+,
) or workspace settings (.vscode/settings.json
). You don‘t have to copy these if you don’t intend to change them.
{ "go.buildOnSave": true, // Run 'go build'/'go test -c' on save. "go.buildTags": "", // The Go build tags to use for all commands that support a `-tags '...'` argument "go.buildFlags": [], // Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ['-ldflags="-s"']) "go.lintOnSave": true, // Run Lint tool on save. "go.lintTool": "golint", // Specifies Lint tool name. Choices are `golint` and `gometalinter` "go.lintFlags": [], // Flags to pass to Lint tool (e.g. ["-min_confidence=.8"]) "go.vetOnSave": true, // Run 'go tool vet' on save. "go.vetFlags": [], // Flags to pass to `go tool vet` (e.g. ['-all', '-shadow']) "go.formatOnSave": true, // Runs formatting tool on save. "go.formatTool": "goreturns", // Pick 'gofmt', 'goimports' or 'goreturns' to run on format. "go.formatFlags": [], // Flags to pass to format tool (e.g. ['-s']) "go.testOnSave": false, // Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled. "go.coverOnSave": false, // Run 'go test -coverprofile' on save "go.testTimeout": "30s", // Specifies the timeout for go test in ParseDuration format. "go.testEnvVars": {}, // Environment variables that will passed to the process that runs the Go tests "go.testFlags": null, // Flags to pass to `go test`. If null, then buildFlags will be used. "go.inferGopath": false, // Infer GOPATH from the workspace root. "go.goroot": null, // Specifies the GOROOT to use when no environment variable is set. "go.gopath": null, // Specifies the GOPATH to use when no environment variable is set. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true. "go.toolsGopath": "", // Location to install the Go tools that the extension depends on if you don't want them in your GOPATH. "go.gocodeAutoBuild": false, // Enable gocode's autobuild feature "go.useCodeSnippetsOnFunctionSuggest": false, // Auto Complete functions with their parameter signature "go.autocompleteUnimportedPackages": false, // Include unimported packages in auto-complete suggestions. "go.docsTool": "godoc", // Pick 'godoc' or 'gogetdoc' to get documentation. In Go 1.5, godoc is used regardless of the choice here. "go.useLanguageServer": false // Experimental: Not available in Windows. Use Go language server from Sourcegraph for Hover, Definition, Find All References, Signature Help, File Outline and Workspace Symbol features "go.addTags": { "tags": "json", // Comma separated tags that will get added by the Add Tags command "options": "json=omitempty", // Comma separated tag options that will get added by the Add Tags command. "promptForTags": false // If true, then user will be prompted to provide tags and options to be added by the Add Tags command. }, "go.removeTags": { "tags": "", // Comma separated tags that will get removed by the Remove Tags command. If empty, all tags are removed. "options": "", // Comma separated tag options that will get removed by the Remove Tags command. "promptForTags": false // If true, then user will be prompted to provide tags and options to be removed by the Remove Tags command. }, "go.editorContextMenuCommands": { // Experimental Feature: Enable/Disable commands from the context menu in the editor. "toggleTestFile": true, "addTags": true, "testAtCursor": true, "generateTestForFunction": true, "addImport": false "removeTags": false, "testFile": false, "testPackage": false, "generateTestForFile": false, "generateTestForPackage": false, "testCoverage": false } }
Set go.useLanguageServer
to true
to use the Go language server from Sourcegraph for features like Hover, Definition, Find All References, Signature Help, Go to Symbol in File and Workspace.
go.useLanguageServer
, you need to reload the VS Code window for it to take effect."go.languageServerFlags": ["-trace"]
"go.languageServerFlags": ["-trace", "-logfile", "path to a text file that exists" ]
A linter is a tool giving coding style feedback and suggestions. By default this extension uses the official golint as a linter.
You can change the default linter and use the more advanced Go Meta Linter by setting go.lintTool
to “gometalinter” in your settings.
Go meta linter uses a collection of various linters which will be installed for you by the extension.
Some of the very useful linter tools:
If you want to run only specific linters (some linters are slow), you can modify your configuration to specify them:
"go.lintFlags": ["--disable-all", "--enable=errcheck"],
Finally, the result of those linters will show right in the code (locations with suggestions will be underlined), as well as in the output pane.
In addition to integrated editing features, the extension also provides several commands in the Command Palette for working with Go files:
Go: Add Import
to add an import from the list of packages in your Go contextGo: Current GOPATH
to see your currently configured GOPATHGo: Test at cursor
to run a test at the current cursor position in the active documentGo: Test Package
to run all tests in the package containing the active documentGo: Test File
to run all tests in the current active documentGo: Test Previous
to run the previously run test commandGo: Generates unit tests for package
Generates unit tests for the current packageGo: Generates unit tests for file
Generates unit tests for the current fileGo: Generates unit tests for function
Generates unit tests for the selected function in the current fileGo: Install Tools
Installs/updates all the Go tools that the extension depends onGo: Add Tags
Adds configured tags to selected struct fields.Go: Remove Tags
Removes configured tags from selected struct fields.To use the debugger, you must currently manually install delve
. See the Installation Instructions for full details. On OS X it requires creating a self-signed cert to sign the dlv
binary.
For more read Debugging Go Code Using VS Code
To remote debug using VS Code, read Remote Debugging
You can set up a development environment for debugging the extension during extension development.
Clone the repo, run npm install
and open a development instance of Code.
git clone https://github.com/Microsoft/vscode-go cd vscode-go npm install code .
You can now go to the Debug viewlet and select Launch Extension
then hit run (F5
).
In the [Extension Development Host]
instance, open any folder with Go code.
You can now hit breakpoints and step through the extension.
If you make edits in the extension .ts
files, just reload (cmd-r
) the [Extension Development Host]
instance of Code to load in the new extension code. The debugging instance will automatically reattach.
To debug the debugger, see the debugAdapter readme.
The extension uses the following tools, installed in the current GOPATH. If any tools are missing, you will see an “Analysis Tools Missing” warning in the bottom right corner of the editor. Clicking it will offer to install the missing tools for you.
If you wish to have the extension use a separate GOPATH for its tools, provide the desired location in the setting go.toolsGopath
. gometalinter
and dlv
are two tools that are exceptions, and will need to be installed in your GOPATH.
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/zmb3/gogetdoc
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/acroca/go-symbols
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/cweill/gotests/...
go get -u -v golang.org/x/tools/cmd/godoc
go get -u -v github.com/fatih/gomodifytags
To install the tools manually in the current GOPATH, just paste and run:
go get -u -v github.com/nsf/gocode go get -u -v github.com/rogpeppe/godef go get -u -v github.com/zmb3/gogetdoc go get -u -v github.com/golang/lint/golint go get -u -v github.com/lukehoban/go-outline go get -u -v sourcegraph.com/sqs/goreturns go get -u -v golang.org/x/tools/cmd/gorename go get -u -v github.com/tpng/gopkgs go get -u -v github.com/acroca/go-symbols go get -u -v golang.org/x/tools/cmd/guru go get -u -v github.com/cweill/gotests/... go get -u -v golang.org/x/tools/cmd/godoc go get -u -v github.com/fatih/gomodifytags
And for debugging: