Mac 下 Vscode 配置 Golang 开发环境
settings.json 配置
{
"python.defaultInterpreterPath": "/Users/yichuan.deng/mkt/env/bin/python",
"editor.fontSize": 16,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"python.pythonPath": "/Users/yichuan.deng/mkt/env/bin/python",
"window.zoomLevel": 1,
"explorer.confirmDelete": false,
"python.formatting.autopep8Args": [
"--indent-size=4"
],
"go.inferGopath": true,
"go.autocompleteUnimportedPackages": true,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.gocodePackageLookupMode": "go",
"go.gotoSymbol.includeImports": true,
"go.docsTool": "gogetdoc",
"go.gopath": "/Users/yichuan.deng/workspace/go",
"go.goroot": "/Users/yichuan.deng/goroot",
"go.formatTool": "goimports",
"go.lintTool": "golint",
"go.lintOnSave": "file",
"go.useLanguageServer": true,
"go.languageServerFlags": [],
"files.autoSave": "off",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": false
},
"terminal.external.linuxExec": "zsh",
"terminal.integrated.fontSize": 16,
"workbench.editorAssociations": [],
"terminal.explorerKind": "external",
"terminal.external.osxExec": "iTerm.app",
"go.alternateTools": {
"go-langserver": "gopls",
},
"go.languageServerExperimentalFeatures": {
"diagnostics": true,
"documentLink": true,
},
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
"editor.semanticTokenColorCustomizations": null,
"editor.codeActionsOnSave": null,
"workbench.colorTheme": "One Dark Pro",
"workbench.iconTheme": "vscode-icons",
"python.showStartPage": false,
"settingsSync.ignoredSettings": [],
"editor.fontLigatures": null,
}
Vscode Go Tools 安装
cmd+shift+P 选择 Go: Install/Update Tools
选择全部,点击确定
Vscode 推荐插件
- Annotator
- Chinese (Simplified) Language Pack for Visual Studio Code
- Go
- Rename terminal Button
- Terminal Tabs
- Git History Diff
- json
- Paste JSON as Codede
Vscode 调试 Golang
点击设置会弹出一个配置JSON,这个就是调试的时候的一些配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}" // 你的工作目录作为调试的根目录,也就是你的main.go 在的地方
"env": { // 调试的时候的环境变量
"env": "DEV",
"tag": "yichuan",
"IS_LOCAL_HOST": "true",
},
}
]
}
开始调试
告别Print调试大法