Go IDE vscode (by quqi99)

Go IDE vscode (by quqi99),第1张

作者:张华 发表于:2021-11-19
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
(http://blog.csdn.net/quqi99 )

之前的CLI方式

之前一直使用cscope和ctag(往前跳和往后跳仍然是Ctrl+O以及Ctrl+I)来查看go代码,

find . ! -name '*test.go' ! -path '*test*' -name '*.go' > cscope.files
cscope -Rbkq
ctags -R
find . ! -name '*test.go' ! -path '*test*' -name '*.go' |xargs -i grep --color -H 'a' {}

并使用YCM (https://github.com/chxuan/vimplus.git)来做代码提示,
同时在~/.vimrc修改了cscope的快捷键, 并添加ConqueGdb用于go调试。

set colorcolumn=80                                                              
set belloff=all                                                                 
let g:ycm_server_python_interpreter = '/usr/bin/python2.7'

" ConqueGdb for go debug - https://michaelthessel.com/go-vim-debugging-with-gdb/
let g:ConqueTerm_Color = 2                                                      
let g:ConqueTerm_CloseOnEnd = 1                                                 
let g:ConqueTerm_StartMessages = 0                                              
                                                                                
function DebugSession()                                                         
    silent make -o vimgdb -gcflags "-N -l"                                      
    redraw!                                                                     
    if (filereadable("vimgdb"))                                                 
        ConqueGdb vimgdb                                                        
    else                                                                        
        echom "Couldn't find debug file"                                        
    endif                                                                       
endfunction                                                                     
function DebugSessionCleanup(term)                                              
    if (filereadable("vimgdb"))                                                 
        let ds=delete("vimgdb")                                                 
    endif                                                                       
endfunction                                                                     
call conque_term#register_function("after_close", "DebugSessionCleanup")        
nmap d :call DebugSession();
if has("cscope")                                                                
   set cscopetag                                                                
   " set to 1 if you want the reverse search order.                             
   set csto=1                                                                   
   " add any cscope database in current directory                               
   if filereadable("cscope.out")                                                
      cs add cscope.out                                                         
   " else add the database pointed to by environment variable                   
   elseif $CSCOPE_DB !=""                                                       
      cs add $CSCOPE_DB                                                         
   endif                                                                        
                                                                                
   " show msg when any other cscope db added                                    
   set cscopeverbose                                                            
   nmap css :cs find s =expand("")                          
   nmap csg :cs find g =expand("")                          
   nmap csc :cs find c =expand("")                          
   nmap cst :cs find t =expand("")                          
   nmap cse :cs find e =expand("")                          
   nmap csf :cs find f =expand("")                          
   nmap csi :cs find i ^=expand("")$                        
   nmap csd :cs find d =expand("")                          
   nmap hello :echo "hello"                                                 
endif                   

基本全部使用CLI, 调试go代码也是使用dlv CLI

现在的GUI方式

但是YCM提示go代码还是不够强大,微软的vscope作为一款GUI的IDE, 可以:

应用商店搜索vim插件安装,这样让使用vscope的习惯和CLI一样。 注意:因为安装了vim插件,所以得按i才能输入字符。别忘了。搜索ai插件安装,让代码提示更智能

现在代码提示是智能了,但仍然有一个不好用的地方,就是包的自动导入。

搜索安装’auto import’插件参考(https://medium.com/backend-habit/setting-golang-plugin-on-vscode-for-autocomplete-and-auto-import-30bf5c58138a)安装一些工具,on VsCode click View -> Command Pallete or type Ctrl+Shift+P and type goinstall update/tools.不用在setting.json中编辑: go.autocompleteUnimportedPackages=True也能生效,注意:是不用。一定要重启vscode,之前一直不行是因为没重启然后保存代码时,会自动导入包。

但是这个功能非常不好用,它是它只能导入标准包,不能导入第三方包。例如对于一个rpc包,我希望导入的是/bak/golang/src/github.com/ethereum/go-ethereum/rpc/,而不是:

import "net/rpc"

按’Ctrl + shift + p"搜"Add import"手动导入包也不能将这个第三方包列出来。

网上说要在setting.json中添加下列参数,试过了,不好使。

 "go.inferGopath": true,

无解了,用得不太顺

用vscode写C

vscode可以编译单个C文件,但对于多个C文件好像不能自动编译,它只是一个编辑器不是一个IDE, 见:
https://www.cnblogs.com/shadowfish/p/12059872.html

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995493.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存