I've written Golang code using Neovim+nvim-cmp. The language server gopls always auto-fills structs with initial values. For example:
a := &MyStruct{}
After saving the file, it modifies the struct to:
a := &MyStruct{
Int1: 0,
String2: "",
//...
PointerN: nil,
}
Seems it only does this if the cursor is currently inside the struct, but still, any way to disable this feature? Or trigger this feature manually by hotkey?
There is an analyzer option fillstruct, described here, which causes the problem and is enabled by default. Problem solved after setting it to false:
lspconfig['gopls'].setup{
cmd = {'gopls'},
--...
settings = {
gopls = {
analyses = {
fillstruct = false,
},
},
},
}
It seems that VSCode also enables this by default, described here, but it doesn't fill it automatically. Instead, it shows a yellow bulb to let user click to do the filling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With