go.nvim icon indicating copy to clipboard operation
go.nvim copied to clipboard

gofmt() fails, goimport() works

Open jhillyerd opened this issue 2 years ago • 5 comments

After updating to a9b6697, (I think I was on 2371bf4 previously), I see the following when my BufWritePre autocommand calls gofmt()

Error detected while processing BufWritePre Autocommands for "*.go":                                                                                                       
Error executing lua callback: ...ames/.local/share/nvim/plugged/go.nvim/lua/go/format.lua:30: attempt to call field 'format' (a nil value)                                 
stack traceback:                                                                                                                                                           
        ...ames/.local/share/nvim/plugged/go.nvim/lua/go/format.lua:30: in function 'run'                                                                                  
        ...ames/.local/share/nvim/plugged/go.nvim/lua/go/format.lua:133: in function 'gofmt'

Running :lua require('go.format').gofmt() shows a similar error.

Manually running goimport() succeeds, as does updating my BufWritePre to call it.

jhillyerd avatar Jul 31 '22 17:07 jhillyerd

If it helps, I have gofmt = 'gopls' in my setup call.

jhillyerd avatar Jul 31 '22 17:07 jhillyerd

I think it is because you are on a neovim version older than 0.7.0. In which the vim.lsp.format is not supported. The override is in lsp.lua. But for some reason, it was disabled in your setup.

ray-x avatar Jul 31 '22 22:07 ray-x

Interesting, I am on 0.7.0. Perhaps there is something wrong with my distro's package. I poke around a bit when I have more time.

jhillyerd avatar Aug 01 '22 15:08 jhillyerd

I was wrong... In fact that should be a change for neovim 0.8.x instead of 0.7.x release. I updated the plugin and you should not see error now.

ray-x avatar Aug 01 '22 15:08 ray-x

@jhillyerd Could you check if it was fixed in the latest?

ray-x avatar Aug 02 '22 09:08 ray-x

Let's see if I remember to do this tonight...

jhillyerd avatar Aug 03 '22 17:08 jhillyerd

Yes, it's fixed. Tested = 99674bb

jhillyerd avatar Aug 04 '22 03:08 jhillyerd