DisposaBoy / GoSublime

A Golang plugin collection for SublimeText 3, providing code completion and other IDE-like features.
MIT License
3.42k stars 302 forks source link

goimports on latest version seems broken #899

Closed jvsteiner closed 5 years ago

jvsteiner commented 5 years ago

I migrated to dev branch, got margo running and chose goimports. after installing the latest version of goimports from golang.org/x/tools/cmd/goimports when I save a file, I am seeing in the console:

margo: Error: failed to fmt /Users/jamie/Code/go/src/github.com/Guardtime/narc/pkg/narc/timecache.go: `goimports -srcdir /Users/jamie/Code/go/src/github.com/Guardtime/narc/pkg/narc/timecache.go`: exit status 2
  Stderr: flag provided but not defined: -srcdir
  usage: goimports [flags] [path ...]
  -d    display diffs instead of rewriting files
  -e    report all errors (not just the first 10 on different lines)
  -l    list files whose formatting differs from goimport's
  -w    write result to (source) file instead of stdout

A little digging reveals that the goimports command must have changed - -srcdir is not the correct command. it prints to stdout by default, with no flags, which is apparently what is required, as changing -srcdir to -w failed with: (and didn't modify the file)

margo: Error: failed to fmt /Users/jamie/Library/Application Support/Sublime Text 3/Packages/GoSublime/src/margo.sh/golang/gofmt.go: fmt completed successfully, but has no output on stdout

removing it entirely also didn't work - in fact it simply rewrote the original, saved version of the file, undoing modifications that I made. I think thats because the goimports is being run on the persisted version of the file, before the save, not after.

DisposaBoy commented 5 years ago

Are you sure you don't have multiple goimports binaries lying round?

If I go get it now, I still see the -srcdir flag.

$ env GOPATH=/tmp go get golang.org/x/tools/cmd/goimports
$ /tmp/bin/goimports -h
usage: goimports [flags] [path ...]
  -cpuprofile string
        CPU profile output
  -d    display diffs instead of rewriting files
  -e    report all errors (not just the first 10 on different lines)
  -l    list files whose formatting differs from goimport's
  -local string
        put imports beginning with this string after 3rd-party packages; comma-separated list
  -memprofile string
        memory profile output
  -memrate int
        if > 0, sets runtime.MemProfileRate
  -srcdir dir
        choose imports as if source code is from dir. When operating on a single file, dir may instead be the complete file name.
  -trace string
        trace profile output
  -v    verbose logging
  -w    write result to (source) file instead of stdout
jvsteiner commented 5 years ago

rebuilt using go get -u must have had an old version in my src dir, but didnt have the binary installed.

jvsteiner commented 5 years ago

loving margo, btw