vim-codefmt icon indicating copy to clipboard operation
vim-codefmt copied to clipboard

Support passing `--srcdir` to goimports

Open dbarnett opened this issue 8 years ago • 3 comments

When using goimports via our gofmt formatter as suggested in the docs, the goimports path-based inference doesn't work because we don't tell goimports about the path. It does support a --srcdir argument we could pass.

We'd have to make it conditional and detect basename(gofmt_executable) == 'goimports' or something like that because gofmt doesn't support any --srcdir arg.

dbarnett avatar Feb 28 '17 17:02 dbarnett

FWIW, goimports is more than a "formatter" and technically is not a "gofmt executable". If we run into a lot of other gotchas like this we may want to reconsider how we're hacking goimports support into codefmt.

dbarnett avatar Feb 28 '17 17:02 dbarnett

Another idea is to cd before running goimports (or whatever tool is configured in gofmt_executable), but it's a bit of a hack when there's already a --srcdir option supported and might have corner case issues (like if you're writing a new file in a subdirectory that doesn't exist yet).

dbarnett avatar Sep 14 '21 18:09 dbarnett

BTW, despite its name, --srcdir accepts the full file path including filename, not just the dir (at least since 2016). We should make it invoke goimports --srcdir=foo/bar.go instead of goimports --srcdir=foo/.

dbarnett avatar Sep 14 '21 18:09 dbarnett