Home > Blockchain >  gopls disable struct auto-fill
gopls disable struct auto-fill

Time:04-12

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?

CodePudding user response:

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.

CodePudding user response:

I do not see that behavior, using latest VSCode 1.66.1, Go 1.18 and gopls 0.32.0, with gopls v0.8.2.

Check first if the issue persists when you remove all other plugins you might have with your VSCode.

  • Related