| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
8年前发布

Visual Studio Code的Go语言开发插件

Visual Studio Code开发工具对Go语言开发的支持,特性包括:

  • Colorization
  • Completion Lists (usinggocode)
  • Snippets
  • Quick Info (usinggodef)
  • Goto Definition (usinggodef)
  • Find References (usinggo-find-references)
  • File outline (usinggo-outline)
  • Rename (usinggorename)
  • Build-on-save (usinggo buildandgo test)
  • Format (usinggoreturnsorgoimportsorgofmt)
  • [partially implemented] Debugging (usingdelve)

IDE Features

IDE

Debugger

IDE

Using

First, you will need to install Visual Studio Code0.10. In the command palette (cmd-shift-p) selectInstall Extensionand chooseGo.

In a terminal window with the GOPATH environment variable set to the GOPATH you want to work on, launchcode. Open you GOPATH folder or any subfolder you want to work on, then open a.gofile to start editing.

Note: It is strongly encouraged to turnAuto Saveon in Visual Studio Code (File -> Auto Save) when using this extension. Many of the Go tools work only on saved files, and error reporting will be more interactive withAuto Saveturned on.

Options

The following Visual Studio Code settings are available for the Go extension. These can be set in user preferences (cmd+,) or workspace settings (.vscode/settings.json).

{      "go.buildOnSave": true,      "go.lintOnSave": true,      "go.vetOnSave": true,      "go.formatTool": "goreturns",      "go.gopath": "/Users/lukeh/go"  }


Optional: Debugging

To use the debugger, you must currently manually installdelve. See the Installation Instructions for full details. This is not yet supported on Windows, and on OS X it requires creating a self-signed cert to sign thedlvbinary.

Once this is installed, go to the Code debug viewlet and select the configuration gear, placing the following in your launch.json:

{      "version": "0.1.0",      "configurations": [          {              "name": "Launch main.go",              "type": "go",              "request": "launch",              "program": "main.go",              "stopOnEntry": false,              "env": {},              "args": [],              "cwd": "."          }      ]  }


Building and Debugging the Extension

You can set up a development environment for debugging the extension during extension development.

First make sure you do not have the extension installed in~/.vscode/extensions. Then clone the repo somewhere else on your machine, runnpm installand open a development instance of Code.

rm -rf ~/.vscode/extensions/lukehoban.Go  cd ~  git clone https://github.com/Microsoft/vscode-go  cd vscode-go  npm install  code . 


You can now go to the Debug viewlet and selectLaunch Extensionthen hit run (F5).

In the[Extension Development Host]instance, open your GOPATH folder.

You can now hit breakpoints and step through the extension.

If you make edits in the extension.tsfiles, 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.

Tools

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.

  • gocode:go get -u -v github.com/nsf/gocode
  • godef:go get -u -v github.com/rogpeppe/godef
  • golint:go get -u -v github.com/golang/lint/golint
  • go-find-references:go get -u -v github.com/lukehoban/go-find-references
  • goreturns:go get -u -v sourcegraph.com/sqs/goreturns
  • gorename:go get -u -v golang.org/x/tools/cmd/gorename

And for debugging:

项目主页:http://www.open-open.com/lib/view/home/1447995873509

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1447995873509.html
Google Go/Golang开发 Go for Visual Studio Code