• vscode 配置 golang开发环境


     

    如果你使用golang,那么强烈建议你采用vscode作为IDE。


    image

    1. 首先在vscode 当中安装go插件,如上图

    2. 配置 %AppData%CodeUsersettings.json 当中的参数

       go.goroot; go.toolsGopath 这两个参数一定要配置上

       vscode配置有两种user,workspace

       user是全局生效,针对所有项目

       workspace仅针对当前项目,如果与user当中的配置不一样,在当前项目中使用workspace的配置   

    "go.formatTool": "goformat",
    "go.goroot": "D:\sdk\go",
    "go.toolsGopath": "D:\sdk\gotools",
    "go.inferGopath": true,
    "go.gotoSymbol.includeGoroot": true,
    "go.gotoSymbol.includeImports": true, 
    "go.useLanguageServer": true,
    "go.autocompleteUnimportedPackages": true,
    "go.coverOnTestPackage": false,

       将上面的配置增加到 settings.json 当中,然后重启vscode

    3. ctrl+shift+p 调出go的命令窗口,然后选择 Go: Install/Update tools

       为什么一定要安装这些工具呢?

       没有这些工具,代码导航、格式化等这些常用功能都不能用,开发的效率和体验会非常不好

    image

    4. 选中所有的工具后,点击OK按钮

    image

    5. 等待下载安装完成即可

     


    错误处理:

    Installing github.com/mdempsky/gocode FAILED

    Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED

    Installing github.com/ramya-rao-a/go-outline FAILED

    Installing github.com/acroca/go-symbols FAILED

    Installing golang.org/x/tools/cmd/guru FAILED

    国内特殊环境引起的,需要自行解决!
    不过,在golang的最新版本中支持使用代理,使用方法如下

    go env -w GOPROXY=https://goproxy.io,direct

     

    如果全部成功将显示下面的提示:

    Installing github.com/mdempsky/gocode SUCCEEDED

    Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED

    Installing github.com/ramya-rao-a/go-outline SUCCEEDED

    Installing github.com/acroca/go-symbols SUCCEEDED

    Installing golang.org/x/tools/cmd/guru SUCCEEDED

    Installing golang.org/x/tools/cmd/gorename SUCCEEDED

    Installing github.com/cweill/gotests/... SUCCEEDED

    Installing github.com/fatih/gomodifytags SUCCEEDED

    Installing github.com/josharian/impl SUCCEEDED

    Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED

    Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED

    Installing github.com/godoctor/godoctor SUCCEEDED

    Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED

    Installing github.com/stamblerre/gocode SUCCEEDED

    Installing github.com/rogpeppe/godef SUCCEEDED

    Installing winterdrache.de/goformat/goformat SUCCEEDED

    Installing golang.org/x/lint/golint SUCCEEDED

    Installing golang.org/x/tools/gopls SUCCEEDED

     

    Reload VS Code window to use the Go language server

    All tools successfully installed. You're ready to Go :).

  • 相关阅读:
    用Xamarin + VS 编写Android程序体验及其与Android Studio的比较
    【Android】XML文件的解析
    【Ubuntu】您没有查看“sf_VirtualDisk”的内容所需的权限。
    Android酷炫实用的开源框架(UI框架)
    Linux下安装gcc 、g++ 、gfortran编译器
    Ubuntu 分辨率调整及操作问题解决
    “this kernel requires an x86-64 CPU, but only detects an i686 CPU, unable to boot” 问题解决
    【Android】沉浸式状态栏实现
    【Android】基于TCP协议的网络通信
    C#中string和byte[]相互转换问题解决
  • 原文地址:https://www.cnblogs.com/russinovich/p/11820098.html
Copyright © 2020-2023  润新知