关于 YouCompleteMe 的 golang 代码提示

2018-04-07 22:20:48 +08:00
 denggj28

最近转到 go 开发,编辑器还是用的 vim 配合 ycm,之前写 py 一直没问题,但是现在写 go,ycm 就不正常了,体现在标准库可以正常提示,第三方的就不行,自定义包有时可以有时不可以。 我是用的 glide,第三方包都是在项目的 vendor 下,我看了 gocode,已经支持 vendor 目录了,是不是 ycm 的 gocode 还是旧版的缘故?看 gocode 是提示找不到库,所以不能提示

附上 ycm 的日志:

Printing YouCompleteMe debug information...
-- Client logfile: /var/folders/n9/3xkfkvg14hg1y5s6gb0rt2hm0000gn/T/ycm_V4rMdM.log
-- Server Python interpreter: /usr/bin/python
-- Server Python version: 2.7.10
-- Server has Clang support compiled in: True
-- Clang version: clang version 6.0.0 (tags/RELEASE_600/final)
-- Extra configuration file found and loaded
-- Extra configuration path: /Users/noisyguy/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py
-- Go completer debug information:
--   Gocode running at: http://127.0.0.1:56711
--   Gocode process ID: 8520
--   Gocode executable: /Users/noisyguy/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/gocode/gocode
--   Gocode logfiles:
--     /var/folders/n9/3xkfkvg14hg1y5s6gb0rt2hm0000gn/T/gocode_56711_stdout_iv8Bgf.log
--     /var/folders/n9/3xkfkvg14hg1y5s6gb0rt2hm0000gn/T/gocode_56711_stderr_ieYfnG.log
--   Godef executable: /Users/noisyguy/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/godef/godef
-- Server running at: http://127.0.0.1:56707
-- Server process ID: 8389
-- Server logfiles:
--   /var/folders/n9/3xkfkvg14hg1y5s6gb0rt2hm0000gn/T/ycmd_56707_stdout_cGL9ys.log
--   /var/folders/n9/3xkfkvg14hg1y5s6gb0rt2hm0000gn/T/ycmd_56707_stderr_Bqz6zK.log

gocode 日志:

696975 2018/04/07 21:43:02 Import path "github.com/json-iterator/go" was not resolved
696976 2018/04/07 21:43:02 Gocode's build context is:
696977 2018/04/07 21:43:02  GOROOT: /usr/local/go
696978 2018/04/07 21:43:02  GOPATH: /Users/noisyguy/go
696979 2018/04/07 21:43:02  GOOS: darwin
696980 2018/04/07 21:43:02  GOARCH: amd64
696981 2018/04/07 21:43:02  BzlProjectRoot: ""
696982 2018/04/07 21:43:02  GBProjectRoot: ""
696983 2018/04/07 21:43:02  lib-path: ""
696984 2018/04/07 21:43:02 Import path "github.com/PuerkitoBio/goquery" was not resolved
696985 2018/04/07 21:43:02 Gocode's build context is:
696986 2018/04/07 21:43:02  GOROOT: /usr/local/go
696987 2018/04/07 21:43:02  GOPATH: /Users/noisyguy/go
696988 2018/04/07 21:43:02  GOOS: darwin
696989 2018/04/07 21:43:02  GOARCH: amd64
696990 2018/04/07 21:43:02  BzlProjectRoot: ""
696991 2018/04/07 21:43:02  GBProjectRoot: ""
696992 2018/04/07 21:43:02  lib-path: ""
696993 2018/04/07 21:43:02 Error parsing input file (inner block):
696994 2018/04/07 21:43:02  160:72: expected selector or type assertion, found ';'
696995 2018/04/07 21:43:02  160:73: missing ',' in argument list
696996 2018/04/07 21:43:02  160:78: expected operand, found ')'
696997 2018/04/07 21:43:02  164:9: expected ')', found 'return'
696998 2018/04/07 21:43:02  164:16: missing ',' in argument list
696999 2018/04/07 21:43:02  164:19: expected operand, found ','
697000 2018/04/07 21:43:02  166:5: missing ',' in argument list
697001 2018/04/07 21:43:02  166:14: missing ',' in argument list
697002 2018/04/07 21:43:02  166:17: expected operand, found 'range'
697003 2018/04/07 21:43:02  170:5: missing ',' in argument list
697004 2018/04/07 21:43:02  170:20: missing ',' before newline in argument list
697005 2018/04/07 21:43:02  171:1: expected operand, found '}'
697006 2018/04/07 21:43:02  171:2: expected ')', found 'EOF'
697007 2018/04/07 21:43:02  171:2: expected ';', found 'EOF'
697008 2018/04/07 21:43:02  171:2: expected ';', found 'EOF'
697009 2018/04/07 21:43:02  171:2: expected ';', found 'EOF'
697010 2018/04/07 21:43:02  171:2: expected '{', found 'EOF'
697011 2018/04/07 21:43:02  171:2: expected '}', found 'EOF'
697012 2018/04/07 21:43:02  171:2: expected '}', found 'EOF'
697013 2018/04/07 21:43:02  171:2: expected '}', found 'EOF'
697014 2018/04/07 21:43:02  171:2: missing ',' in argument list
697015 2018/04/07 21:43:02 extracted expression tokens: titleTag.First()
697016 2018/04/07 21:43:02 Offset: 0
697017 2018/04/07 21:43:02 Number of candidates found: 0
697018 2018/04/07 21:43:02 Candidates are:
4062 次点击
所在节点    Go 编程语言
39 条回复
wlwood
2018-04-08 07:32:11 +08:00
Emacs 也是,需要先 go install。然后第三方代码才能提示。
bolide2005
2018-04-08 07:34:08 +08:00
@glues 恕我直言,一周时间都搞不定环境的工具有什么效率可言?
introom
2018-04-08 07:36:54 +08:00
ide 也许对大多数人好,但在一些开发环境,vim 或者 Emacs 才是最方便。 哪些所谓的折腾,到最後都会 pay off. 除非你实在闲的没事做,折腾太过。
bolide2005
2018-04-08 08:18:24 +08:00
FYI,pycharm 和 goland 的 vim mode 各位了解一下,配合 IDE 本身的快捷键,全键盘操作体验更好
kiwi95
2018-04-08 08:58:13 +08:00
等你折腾一年的 vim 的时候就会说 vim 才是真正的生产力工具了,什么 IDE 的 vim 模式也一般就是个玩具。虽然刚开始 vim 有很多不方便,但一个顺手的工具是值得花时间去打磨和练习的,这些学习成本能带来极大的效率提升和成就感。

当然喜欢 IDE 的也没问题,但请不要随便定义什么生产力工具。
fatttt
2018-04-08 10:02:12 +08:00
@denggj28 把 go 插件的设置一下: "go.gocodeAutoBuild": false 试试。有时候 vsc 确实会抽风 cpu 用完,我用 htop 发现都是 gocode 的锅。
tomychen
2018-04-08 14:01:21 +08:00
没写过 go 但 c 来讲 neocomplcache 个人感觉比 YCM 更顺手和安逸
ylcc
2018-04-08 14:03:29 +08:00
GoLand
markx
2018-04-08 14:31:29 +08:00
会用 vim 的话,vim 对 go 的支持还是挺好的。 不用 vim 的话,我感觉 vscode 也很不错。

我个人觉得没有必要过于鼓吹自己的偏好。效率高不高,自己干活才知道。
Immortal
2018-04-08 14:41:03 +08:00
还是无脑推荐 goland+vim 插件
danielzhang0212
2018-04-08 15:32:59 +08:00
配置环境也算是爱好了。
WangYanjie
2018-04-08 15:39:19 +08:00
@bolide2005 第一 用 IDE 还是 vim,其实本质上是看你想要 IDE/vim 提供什么。第二 从我的经验来说 vim 并不落后。
ABCDXYZs
2018-04-08 17:15:56 +08:00
两行命令,无比简洁
sudo apt-get install vim-youcompleteme
vim-addons install youcompleteme
leopku
2018-04-08 17:18:00 +08:00
竟然没人提 oni
BBCCBB
2018-04-08 21:15:47 +08:00
推荐用 deoplete|nvim-completion-manager,配置简单
ivechan
2018-04-08 21:27:11 +08:00
只是写 go 的话,可以用官方的 go 插件,体验还行。
https://github.com/fatih/vim-go
denggj28
2018-04-08 21:38:16 +08:00
@ivechan 多谢推荐,不过我要写 c cpp py go,偶尔还要写些前端,自己配的 vim 习惯了
jzdxeb
2018-04-09 09:39:15 +08:00
试试 安装一个 vim-go 试试?
golang83
2019-05-06 21:13:26 +08:00
@denggj28
哥们,使用 vim-go,<c-x> <x-o>就可以了。或则你在做个 map 映射一下一个快捷键提示,ycm 默认的代码提示等太烦人了。自己就跑出来了。老子打个 Println 还需要你妹的提示呀。
如果你非要在 ycm 里面更好的支持第三方包,改改 vim ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/github.com/mdempsky/gocode/internal/
里的 gocode 源代码...

顺便吐槽一下,ycm 太几把重了... 编译又是 install.py 又是 gcc 又是 g++,尼玛自动补全又用 python 写个 completer.py 去调 gocode....

一个插件老子在某些 vps 上编译要 30 分钟。。曹。。。。。。一个 C++游戏服务器的重新 build 一下也不过 30 分钟

为了吐槽和帮你,我专门注册的这个网站,网站的问题也是搞笑,问我一个 ip 段属于那个公司..............
我以为程序员开发的东西不是应该保持 simple & easy to use 的嘛..

还有 vscode 哪里不好? vim 嘛是情怀,vscode 嘛也是情怀,微软就是情怀... ibm pcdos -> msdos -> win2 -> win3.1 -> win95 -> win98 -> winme -> win2000 -> compaq digital unix -> linux -> winxp -> winvista .... win10
对于我这种 91 年用电脑的人来说,dos borland c++ / vi/vim 就是情怀。我们用了那么多年的微软产品,visual studio 到现在 vscode,微软出品必属精品。其他的就用过 eclipse 和 andriod studio,写 html/css/js 感觉 editplus zen coding 这类轻量级文本编辑器完爆 n 多所谓的 IDE
goland 还要收钱??我的天...

还有 linux 下 go 的调试也可以在界面里面使用 vim-go,麻烦第一点的是清除断点,需要使用 sign,或则在 cli 下直接 dlv 都挺好,go 也可以用 gdb 调试 ,不过 golang.org 也推荐 dlv。
augroup godebug
290 au! * <buffer>
291 " 设置 dlv for vim-go-debug 的按键
292 au FileType go nnoremap <buffer><F5> :GoDebugContinue<CR>
293 au FileType go nnoremap <buffer><F6> :GoDebugPrint<CR>
294 au FileType go nnoremap <buffer><F7> :GoDebugStart<CR>
295 au FileType go nnoremap <buffer><F8> :GoDebugStop<CR>
296 au FileType go nnoremap <buffer><F9> :GoDebugBreakpoint<CR>
297 au FileType go nnoremap <buffer><F10> :GoDebugNext<CR>
298 au FileType go nnoremap <buffer><F11> :GoDebugStep<CR>
299 " 清除断点,清除前最好 sing place 一下,下面的是全部清除
300 au FileType go nnoremap <buffer><F12> :sign unplace *<CR>
301 augroup END
302 doautocmd godebug Filetype go

sign place 列出断点 id,单独清除可以在 vimrc 写个函数,先获取 corsor 的位置,然后获取行号,然后单独清除
但是手动也挺快。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/444922

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX