This article is outdated, please check Setting up lsp + gopls + rust_analyzer in neovim since neovim has a built in lsp client now.


I spent more time than I’d like to admit trying to figure out how to convert a json object to a vim dict.

And then I gave up and went with using NeoVim’s built in py3eval to make my life easier.

~/.config/nvim/init.vim

let g:go_auto_type_info = 1
let g:go_auto_sameids = 1
let g:go_updatetime = 500
let g:go_fillstruct_mode = 'gopls'
let g:go_metalinter_command = 'gopls'
let g:go_term_reuse = 1
let g:go_term_enabled = 1
"let g:go_debug = ["lsp"]

python3 << EOF
import vim
import json

gopls_cfg = json.loads("""{
	"formatting.gofumpt": true,
	"ui.diagnostic.staticcheck": true,
	"ui.diagnostic.analyses": {
		"ST1000": false,
		"ST1003": false,
		"SA5001": false,
		"nilness": true,
		"unusedwrite": true,
		"fieldalignment": true,
		"shadow": false,
		"composites": false
	},
	"ui.codelenses": {
		"generate": true,
		"regenerate_cgo": true,
		"test": true,
		"vendor": true,
		"tidy": true,
		"upgrade_dependency": true,
		"gc_details": true
	},
	"ui.diagnostic.annotations": {
		"bounds": true,
		"inline": true,
		"escape": true,
		"nil": true
	},

	"ui.completion.usePlaceholders": true,
	"ui.navigation.importShortcut": "Definition",
	"ui.completion.completionBudget": "500ms",

	"build.allowImplicitNetworkAccess": true,
	"build.directoryFilters": ["-node_modules", "-data"],

	"ui.diagnostic.experimentalDiagnosticsDelay": "300ms",
	"ui.completion.experimentalPostfixCompletions": true,
	"build.experimentalTemplateSupport": true,
	"build.experimentalPackageCacheKey": true
}""")
EOF

let g:go_gopls_settings = py3eval("gopls_cfg")