Vscode 对于 go 代码太过严苛
简介
Vscode 对于 go 代码太过严苛
问题
Vscode
对 go
代码要求过于严苛,可能会出现闪烁等问题。
解决
打开 settings.json
文件,配置如下
{
"go.inferGopath": false,
"go.lintFlags": [
"-min_confidence=.8"
],
}
一份具体的配置:
{
"go.useLanguageServer": true,
"timeline.excludeSources": [],
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"gopls": {
"completeUnimported": true,
"usePlaceholders": true,
"completionDocumentation": true,
"deepCompletion": true,
"matcher": "fuzzy",
"hoverKind": "SynopsisDocumentation" // No/Synopsis/Full, default Synopsis
},
"files.eol": "\n", // formatting only supports LF line endings
"go.languageServerExperimentalFeatures": {
"format": true,
"autoComplete": true,
"rename": true,
"goToDefinition": true,
"hover": true,
"signatureHelp": true,
"goToTypeDefinition": true,
"goToImplementation": true,
"documentSymbols": true,
"workspaceSymbols": true,
"findReferences": true,
"diagnostics": false
},
"emmet.excludeLanguages": [
"markdown"
],
"go.addTags": {
},
"go.inferGopath": false,
"go.lintFlags": [
"-min_confidence=.8"
],
}
扩展
当go的项目目录不是根目录时,可能引入的包会爆红,无法跳转
解决方法是:在根目录建一个.vscode
目录,里面放一个settings.json
文件
-.vscode
—settings.json
settings.json
文件内容如下:
{
"go.inferGopath": false,
"gopls": {
"experimentalWorkspaceModule": true
},
}
重启vscode,解决