ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2.12k stars 124 forks source link

'golines failed 1' each time running :GoFmt #266

Closed ybbond closed 1 year ago

ybbond commented 1 year ago

On first install, I already do :GoInstallBinaries

I only set:

require('go').setup({
  gofmt = 'gopls',
})

on setup.

Using go version go1.16.15 darwin/arm64, and because go <1.18 should use golines v0.9.0, I also install golines manually via

go install github.com/segmentio/golines@v0.9.0

Other than formatting, function like hover, auto-import, search reference all working fine

ray-x commented 1 year ago

golines command failed as the exit code is 1 What happens if you run it directly from your terminal?

ybbond commented 1 year ago

running golines directly in terminal will either output the format result[^1] or it can also write[^2]

[^1]: golines server/server.go [^2]: golines server/routes.go -w

ray-x commented 1 year ago

What is the status code after run golines

echo $?

If status is 0 you have to enable the log by

  require("go").setup({
    verbose = true,
    gofmt = "gofumpt",
    log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log",
}

The log path will be ~/tmp/gonvim.log

ybbond commented 1 year ago

status code for golines is 0.

not too long log file
  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/golang/mock@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/vuln/cmd/govulncheck@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/segmentio/golines@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/gopls@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "gotest.tools/gotestsum@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/golang/mock@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/gopls@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/abenz1267/gomvp@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/fatih/gomodifytags@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/segmentio/golines@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/cweill/gotests/...@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/go-delve/delve/cmd/dlv@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/tmc/json-to-struct@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/vuln/cmd/govulncheck@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/koron/iferr@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/davidrjenni/reftools/cmd/fillstruct@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/davidrjenni/reftools/cmd/fillswitch@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/josharian/impl@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/cmd/gorename@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/cmd/callgraph@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/cmd/goimports@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/cmd/guru@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/kyoh86/richgo@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "mvdan.cc/gofumpt@latest" }

  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/onsi/ginkgo/v2/ginkgo@latest" }

  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:116 |1: {}

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/segmentio/golines@latest" }

  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:116 |1: {}

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "github.com/segmentio/golines@latest" }

  ...e/nvim/site/pack/packer/start/go.nvim/lua/go/install.lua:66 |1: { "go", "install", "golang.org/x/tools/gopls@latest" }

  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  .../nvim/site/pack/packer/start/go.nvim/lua/go/codelens.lua:7 |1: enable codelens
  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:116 |1: {}

  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:29 |1: { "--max-len=128", "--base-formatter=gopls" }
 |2: 0
  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:48 |1: formatting buffer... { "--max-len=128", "--base-formatter=gopls", "/Users/yohanesbandung/go/src/gitlab.com/pinvest/backends/notification/server/routes.go" } |2: 1
  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:62 |1: fmt cmd: |2: { "golines", "--max-len=128", "--base-formatter=gopls", "/Users/yohanesbandung/go/src/gitlab.com/pinvest/backends/notification/server/routes.go" }

  ...re/nvim/site/pack/packer/start/go.nvim/lua/go/format.lua:83 |1: { "[2023-01-05 14:15:24] FATAL Error formatting source: exit status 2" } from stderr

If you need me to do something specific as test case, do let me know


now, everytime I do command :GoFmt, it will output :messages:

gopls installed, use GoUpdateBinary to update it
golines installed, use GoUpdateBinary to update it
Press ENTER or type command to continue
ray-x commented 1 year ago

I think it relates to --base-formatter=gopls Would you

require('go').setup({
  gofmt = 'gofumpt',
})
ybbond commented 1 year ago

It works normally with gofumpt! Thank you.

But If I test formatting in some files, gofumpt reformat the docs that already formatted with my company's default (gopls)


so then I tried changing

require('go').setup({
  gofmt = 'gopls',
})

and some thing I notice is:

  1. if I open a *.go file
  2. I make edits that intentionally unformat the file
  3. I done make edits and I don't :write the doc
  4. I trigger :GoFmt
  5. the file will be reformatted
  6. the buffer state will be modified / 'dirty'

I will expect, that if I make undo, the buffer will be in 'written' state:

instead, the 'written' state will be on (3).


I think because this plugin need the buffer to be in written to disc before comparing and formatting, so there are some vim.cmd('write') on the format.lua file.

but in my behavior when using gofmt = 'gopls', the file will be on modified state after done formatting document.

ray-x commented 1 year ago

gopls use different vim.cmd('write') https://github.com/ray-x/go.nvim/blob/26fd07ebada5035d54459f09813e8738d0517676/lua/go/format.lua#L35-L37