Go语言有什么好用的IDE吗

Python017

Go语言有什么好用的IDE吗,第1张

我喜欢jetbrains系列的IDE+go插件。不过我要说的是这个问题主要看你的观点如何。

说eclipse:

构建方式是使用go install 命令,每一次编译运行都是go install。这样的好处就是如果你有很多的包,下载下来并没有编译,这样每次编译速度是很快的。而且(!)go install 符合go官方的项目结构,官方说过了,一个go的项目应该是以个gopath,包含src,pkg,bin三个主要目录。所以说go install个人认为才是主要的go编译方式。

说eclipse的缺点:

其实eclipse插件的go编译方式,还有目录结构,项目结构,都是非常完美的!!!!真的很完美!可是,他的代码提示,太差件!大括号都不能自动补全,gdb 32bit 64bit兼容问题,eclipseC++ 没有html js插件,需要手动安装,几乎不能开箱即用。不过如果你是开发算法,数据处理,还是推荐eclipse的,毕竟其他都无关紧要。

说jetbrains:

说先说clione肯定不适合,新建项目没有向导,导致改成go项目各种不开心,比如图标对于我来说就无法接受go lib 不是小耗子~这是次要的,重要的是各个文件都是灰色的(没有在cmake中包含的结果),然后说剩下的,phpstorm这个不说了,估计很少有人插件按在这里,webstorm,体验也不是很好,idea?体验很好,可是毕竟比较重,尤其是现在加入了自家的K啥玩意(无意冒犯,没记住单词)~可是话说回来,go跟C系列IDE配合才是最佳,跟java系列一点不搭关系,用idea似乎有点格格不入,但是!idea支持新建项目向导,lib的图标也很清晰,最后还是选择idea吧,期待clion的强大起来!

再说jetbrains系列缺点:

插件的构建方式是go buiild 这个让人很不爽,我们几乎不确定会构建到什么地方去,还要每次设置一下run配置。这个可能无关紧要,毕竟不是什么大的毛病,可是go build不能缓存.a文件,直接构建的结果就是很多第三方包的情况下很慢!所以建议安装包的时候手动install 一下解决这个问题。自带代码格式化,这个格式化跟go 格格不入,总的来说就是蛋疼,心碎,菊花痒。

最后说liteIDE:

轻量级IDE,我可以说是国人GO伟大作品典范,然而默认构建也是go build,项目管理方式不符合go官方标准。代码提示不能自动导入(eclipse也不能),不过如果你的项目是以包为单位的,那么另当别论。一定很不错,毕竟是轻量级专门针对GO的IDE!

说这些,其实还有很大一部分取决于你的项目是用vendor机制管理,还是godeps机制管理依赖关系。go不像java拥有强大的几乎天下一统的maven(无意冒犯,暂不评价其他构建套件)。

go没有官方包仓库。

go没有官方包管理工具。

go没有官方自动化构建套件。

上面三个没有是致命要害。导致民间各种百花齐放。

说说我的项目怎么管理

gpm 一个shell工具(windows下你可以用git的bash,或者cygwin~)

我是严格艳照官方推荐方式管理go项目,一个go项目一个gopath。系统的gopath只是为了安装go命令,我没有配置gobin,意义不大。

项目的依赖跟我的代码包都在src下(非vendor)

vendor用来存放包的特殊依赖,发布项目直接把依赖包发布上去(公网管理则只上传依赖关系文件 godeps文件)

资源文件等都放在src目录同级,编译文件放在bin,引用直接../引用。

第一种:LiteIDE

LiteIDE是一个简单的开源IDE,值得注意的是,它是GO语言2012年正式版发布的首个IDE,由Qt开发,它看起来类似于Visual Studio等其他编译器。

由于它是为golang设计的,LiteIDE为开发人员提供了许多有用的功能,包括可配置的构建命令,高级代码编辑器和广泛的golang支持。其他功能包括代码管理、gdb、Delve调试器、自动完成和使用WordApi的主题,基于MIME类型的系统等。

第二种:VS Code

它是微软开发的广受欢迎的开源IDE,有一个开箱即用的go扩展可供VS Code使用。VS Code插件为开发人员提供了很多功能,包括与许多go工具集成。

VS Code通过IntelliSense,内置git集成,直接从编译器调试代码等功能提供智能完成功能VS Code具有高度可扩展性,并通过其许多扩展提供了许多自定义选项,还提供了几十种语言的支持,成为受开发者欢迎的工具。

第三种:Atom

开发人员可以利用这个Atom IDE改进的语言集成与更智能的编辑器。开源的go-plus软件包使开发人员更容易在GO中进行编程。

Atom和go-plus软件包为golang提供工具,构建流程,linters、vet和coverage工具的支持其他功能包括自动完成、格式化、测试和文档。

第四种:Vim

Vim有许多插件可以帮助开发人员更轻松地编辑他们的GO代码Vim-go插件自动安装所有必要的东西,为Vim中的GO开发人员提供更平滑的集成。

Vim-go具有许多有用的功能,包括编译器,改进的语法高亮和折叠,完成支持以及一系列具有集成支持的调试程序。还有一些使用的高级源分析工具,包括GoImplements、GoCallees和GoReferrers。

1、编译vimgdb

下载vimgdb73和vim73

mkdir -p ./tmp

cd tmp

tar zxvf ../vim-7.3.tar.gz

unzip ../vimgdb-for-vim7.3-master.zip

mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3

patch -p0 <vimgdb-for-vim7.3/vim73.patch

cd vim73

安装依赖

sudo apt-get install build-essential

sudo apt-get build-dep vim-gtk

sudo apt-get install libncurses5-dev

安装

// 这里直接执行make的操作

make

sudo make install

安装vimgdb runtime

cd ../vimgdb-for-vim7.3

cp vimgdb_runtime ~/.vim/bundle

打开vim

:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件

添加配置.vimrc

" vimgdb插件

run macros/gdb_mappings.vim

在vim中执行gdb时,报 “Unable to read from GDB pseudo tty” 的错误,因为没有安装 gdb ,所以安装gdb

sudo apt-get install gdb

2、安装vundle

set up vundle

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Configure Plugins

在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉

set nocompatible " be iMproved, required

filetype off " required

" set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

" alternatively, pass a path where Vundle should install plugins

"let path = '~/some/path/here'

"call vundle#rc(path)

" let Vundle manage Vundle, required

Plugin 'gmarik/vundle'

" The following are examples of different formats supported.

" Keep Plugin commands between here and filetype plugin indent on.

" scripts on GitHub repos

Plugin 'tpope/vim-fugitive'

Plugin 'Lokaltog/vim-easymotion'

Plugin 'tpope/vim-rails.git'

" The sparkup vim script is in a subdirectory of this repo called vim.

" Pass the path to set the runtimepath properly.

Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" scripts from http://vim-scripts.org/vim/scripts.html

Plugin 'L9'

Plugin 'FuzzyFinder'

" scripts not on GitHub

Plugin 'git://git.wincent.com/command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)

Plugin 'file:///home/gmarik/path/to/plugin'

" ...

filetype plugin indent on " required

" To ignore plugin indent changes, instead use:

"filetype plugin on

"

" Brief help

" : PluginList - list configured plugins

" : PluginInstall(!)- install (update) plugins

" : PluginSearch(!) foo - search (or refresh cache first) for foo

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

"

" see :h vundle for more details or wiki for FAQ

" NOTE: comments after Plugin commands are not allowed.

" Put your stuff after this line

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

3、官方vim-lang插件

Config vim file .vimrc,Add content bellow in bottom of the file

" 官方的插件

" Some Linux distributions set filetype in /etc/vimrc.

" Clear filetype flags before changing runtimepath to force Vim to

" reload them.

filetype off

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre Fmt

4、代码补全的插件gocode

配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式

export GOROOT=/usr/local/go

export GOPATH=/data/app/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Set up gocode

Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:

go get -u github.com/nsf/gocode (-u flag for "update")

Configure vim in .vimrc file

Plugin 'nsf/gocode', {'rtp': 'vim/'}

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

写一个helloword程序,输入fmt后按<C-x><C-o>如果能看到函数的声明展示出来,说明安装是正确的。

4、代码跳转提示godef

Set up godef

go get -v code.google.com/p/rog-go/exp/cmd/godef

go install -v code.google.com/p/rog-go/exp/cmd/godef

git clone https://github.com/dgryski/vim-godef ~/.vim/bundle/vim-godef

Configure vim in .vimrc file

Bundle 'dgryski/vim-godef'

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

5、代码结构提示gotags

Set up gotags

go get -u github.com/jstemmer/gotags

Put the following configuration in your vimrc:

Bundle 'majutsushi/tagbar'

nmap :TagbarToggle

let g:tagbar_type_go = {

\ 'ctagstype' : 'go',

\ 'kinds' : [

\ 'p:package',

\ 'i:imports:1',

\ 'c:constants',

\ 'v:variables',

\ 't:types',

\ 'n:interfaces',

\ 'w:fields',

\ 'e:embedded',

\ 'm:methods',

\ 'r:constructor',

\ 'f:functions'

\ ],

\ 'sro' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置。

再次按会关闭tag窗口。

PS:本地的.vimrc的配置

" 插件管理器 vundle

set nocompatible " be iMproved, required

filetype off " required

" set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

" alternatively, pass a path where Vundle should install plugins

"let path = '~/some/path/here'

"call vundle#rc(path)

" let Vundle manage Vundle, required

Plugin 'gmarik/vundle'

" The following are examples of different formats supported.

" Keep Plugin commands between here and filetype plugin indent on.

" scripts on GitHub repos

" Plugin 'tpope/vim-fugitive'

" Plugin 'Lokaltog/vim-easymotion'

" Plugin 'tpope/vim-rails.git'

" The sparkup vim script is in a subdirectory of this repo called vim.

" Pass the path to set the runtimepath properly.

" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" scripts from http://vim-scripts.org/vim/scripts.html

" Plugin 'L9'

" Plugin 'FuzzyFinder'

" scripts not on GitHub

" Plugin 'git://git.wincent.com/command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)

" Plugin 'file:///home/gmarik/path/to/plugin'

" ...

"

filetype plugin indent on " required

" To ignore plugin indent changes, instead use:

" filetype plugin on

"

" Brief help

" : PluginList - list configured plugins

" : PluginInstall(!) - install (update) plugins

" : PluginSearch(!) foo - search (or refresh cache first) for foo

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

"

" see :h vundle for more details or wiki for FAQ

" NOTE: comments after Plugin commands are not allowed.

" Put your stuff after this line

syntax on

" ********************************************************************

" 这里省略了其它不相关的插件

" vimgdb插件

run macros/gdb_mappings.vim

" 官方的插件

" Some Linux distributions set filetype in /etc/vimrc.

" Clear filetype flags before changing runtimepath to force Vim to

" reload them.

filetype off

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre <buffer>Fmt

" 代码补全的插件

Bundle 'Blackrush/vim-gocode'

" 代码跳转提示

Bundle 'dgryski/vim-godef'

" 代码结构提示

Bundle 'majutsushi/tagbar'

nmap <F8>:TagbarToggle<CR>

let g:tagbar_type_go = {

\ 'ctagstype' : 'go',

\ 'kinds' : [

\ 'p:package',

\ 'i:imports:1',

\ 'c:constants',

\ 'v:variables',

\ 't:types',

\ 'n:interfaces',

\ 'w:fields',

\ 'e:embedded',

\ 'm:methods',

\ 'r:constructor',

\ 'f:functions'

\ ],

\ 'sro' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }