Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么让VSCODE 支持运行Go程序 #90

Open
kevinyan815 opened this issue Aug 31, 2023 · 0 comments
Open

怎么让VSCODE 支持运行Go程序 #90

kevinyan815 opened this issue Aug 31, 2023 · 0 comments

Comments

@kevinyan815
Copy link
Owner

下载安装VSCODE

下载地址:https://code.visualstudio.com/Download
image

选择自己电脑对应平台的VsCode进行下载。

安装Go 扩展

安装完VsCode后,先安装Go官方的扩展,去VsCode插件市场搜索Go,选择扩展进行安装,如下图:
image

安装 GO Tools

按住快捷键:CMD + SHIFT + P
弹出下面安装窗口
image
输入:Go:install/Update Tools
image
image

  • VsCode 支持开发Go项目主要依赖 gopls 这个工具,该工具现在最新版最低要求Go1.18 所以需要升级Go版本,并设置GOPATH环境变量。

配置Go 项目运行

打开项目后,按F5 运行项目,首次会提示配置launch.json, 该文件位于项目根目录的.vscode文件夹下

进行如下配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceFolder}",
            "env": {},
            "args": []
        }
    ]
}

设置Go语法不全和包自动引入

如果用惯了Goland,会发现VsCode写Go代码时自动引入包,代码补全非常卡顿半天也完不成,这个在VsCode也是靠gopls实现,我们需要配置VsCode自动保存代码更改的频率,把间隔设置短一点就不会察觉这么卡顿了

image image 按照上图操作,找到自动保存的配置,把auto save delay 的延迟时间设置的短一点就可以了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant