go.nvim
go.nvim copied to clipboard
gofmt() fails, goimport() works
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.
If it helps, I have gofmt = 'gopls'
in my setup call.
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.
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.
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.
@jhillyerd Could you check if it was fixed in the latest?
Let's see if I remember to do this tonight...
Yes, it's fixed. Tested = 99674bb