首先,需要安裝好 go 插件,插件市場搜索go,選一個即可安裝。
然后,需要安裝 go 的工具包。在 vscode 中,輸入快捷鍵:command(ctrl) + shift + p,在彈出的窗口中,輸入:go:install/Update Tools,回車后,選擇所有插件(勾一下全選),點擊確認,進行安裝(設置GOPROXY)。
接下來,在項目的 settings.json 文件中添加配置:
"go.goroot": "D:\\Go",
"go.gopath": "D:\\gopath",
//第三方庫代碼提示
"go.inferGopath": true,
"go.formatTool": "goreturns",
//自動完成未導入的包
"go.autocompleteUnimportedPackages": true,
"go.gocodePackageLookupMode": "go",
"go.gotoSymbol.includeImports": true,
"go.docsTool": "gogetdoc",
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.useLanguageServer": true,
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
}, // Optional: Disable snippets, as they conflict with completion ranking. "editor.snippetSuggestions": "none",
},"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},"go.trace.server": "verbose",
"gopls": {
// Add parameter placeholders when completing a function.
"usePlaceholders": false,
// If true, enable additional analyses with staticcheck.
// Warning: This will significantly increase memory usage. "staticcheck": false,
},"go.languageServerFlags": [
"-remote=auto", "-logfile=auto", "-debug=:0", "-rpc.trace",
],
首選項-設置 去掉 Use Language Server