|
1 |
| -# vscode-go |
2 |
| -An extension for VS Code with provides support for the Go language. |
| 1 | +# Go for Visual Studio Code |
| 2 | + |
| 3 | +This Code extension adds rich language support for the Go language, including: |
| 4 | + |
| 5 | +- Colorization |
| 6 | +- Completion Lists (using `gocode`) |
| 7 | +- Snippets |
| 8 | +- Quick Info (using `godef`) |
| 9 | +- Goto Definition (using `godef`) |
| 10 | +- Find References (using `go-find-references`) |
| 11 | +- File outline (using `go-outline`) |
| 12 | +- Rename (using `gorename`) |
| 13 | +- Build-on-save (using `go build` and `go test`) |
| 14 | +- Format (using `goreturns` or `goimports` or `gofmt`) |
| 15 | +- [partially implemented] Debugging (using `delve`) |
| 16 | + |
| 17 | +For bug reports and/or feedback, email `lukeh` or [open a bug ](https://monacotools.visualstudio.com/DefaultCollection/Monaco/_workItems#_a=new&witd=Bug&%5BSystem.Title%5D=Go%3A&%5BSystem.AreaPath%5D=Monaco%5CGo) under the `Monaco\Go` area path. |
| 18 | + |
| 19 | +## Using |
| 20 | + |
| 21 | +First, you will need to install Visual Studio Code 0.9.*. |
| 22 | + |
| 23 | +Next, clone this repo into your Code extensions folder and run `npm install`. |
| 24 | + |
| 25 | +```bash |
| 26 | +cd ~/.vscode/extensions/ |
| 27 | +git clone https://monacotools.visualstudio.com/DefaultCollection/Monaco/_git/go-code |
| 28 | +cd go-code |
| 29 | +npm install |
| 30 | +``` |
| 31 | + |
| 32 | +In a terminal window with the GOPATH environment variable set to the GOPATH you want to work on, launch `code`. Open you GOPATH folder or any subfolder you want to work on, then open a `.go` file to start editing. |
| 33 | + |
| 34 | +### _Optional_: Debugging |
| 35 | + |
| 36 | +To use the debugger, you must currently manually install `delve`. See the [Installation Instructions](https://github.com/derekparker/delve/wiki/Building) for full details. This is not yet supported on Windows, and on OS X it requires creating a self-signed cert to sign the `dlv` binary. |
| 37 | + |
| 38 | +Once this is installed, go to the Code debug viewlet and select the configuration gear, placing the following in your launch.json: |
| 39 | + |
| 40 | +```json |
| 41 | +{ |
| 42 | + "version": "0.1.0", |
| 43 | + "configurations": [ |
| 44 | + { |
| 45 | + "name": "Delve test", |
| 46 | + "type": "go", |
| 47 | + "program": "/Users/lukeh/dd/go/src/github.com/lukehoban/azuretest/test.go" |
| 48 | + } |
| 49 | + ] |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Building and Debugging the Extension |
| 54 | + |
| 55 | +You can set up a development environment for debugging the extension during extension development. |
| 56 | + |
| 57 | +First make sure you do not have the extension installed in `~/.vscode/extensions`. Then clone the repo somewhere else on your machine, run `npm install` and open a development instance of Code. |
| 58 | + |
| 59 | +```bash |
| 60 | +rm -rf ~/.vscode/extensions/go-code |
| 61 | +cd ~ |
| 62 | +git clone https://monacotools.visualstudio.com/DefaultCollection/Monaco/_git/go-code |
| 63 | +cd go-code |
| 64 | +npm install |
| 65 | +code . |
| 66 | +``` |
| 67 | + |
| 68 | +To build, use the `Tasks: Run Build Task` command (`cmd-shift-B`). This will start a build watcher so that .ts files are compiled on save. |
| 69 | + |
| 70 | +You can now go to the Debug viewlet and select `Launch Extension` then hit play (`F5`). |
| 71 | + |
| 72 | +In the `[Extension Development Host]` instance, open your GOPATH folder. |
| 73 | + |
| 74 | +You can now hit breakpoints and step through the extension. |
| 75 | + |
| 76 | +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. |
| 77 | + |
| 78 | +## Tools |
| 79 | + |
| 80 | +The extension uses the following tools, installed in the current GOPATH. If any tools are missing, the extension will offer to install them for you. |
| 81 | + |
| 82 | +- gorename: `go get -u -v golang.org/x/tools/cmd/gorename` |
| 83 | +- gocode: `go get -u -v github.com/nsf/gocode` |
| 84 | +- goreturns: `go get -u -v sourcegraph.com/sqs/goreturns` |
| 85 | +- godef: `go get -u -v github.com/rogpeppe/godef` |
| 86 | +- golint: `go get -u -v github.com/golang/lint/golint` |
| 87 | +- go-find-references: `go get -u -v github.com/lukehoban/go-find-references` |
| 88 | + |
| 89 | +And for debugging: |
| 90 | + |
| 91 | +- delve: `go get -u -v github.com/derekparker/delve/cmd/dlv` |
| 92 | + |
| 93 | +## Demos |
| 94 | + |
| 95 | +### IDE Features |
| 96 | + |
| 97 | + |
| 98 | +### Debugger |
| 99 | + |
0 commit comments