Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gopls disable struct auto-fill

Tags:

go

gopls

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?

like image 765
aj3423 Avatar asked Jun 09 '26 16:06

aj3423


1 Answers

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.

like image 188
aj3423 Avatar answered Jun 12 '26 08:06

aj3423