google / vim-codefmt

Vim plugin for syntax-aware code formatting
Apache License 2.0
1.11k stars 114 forks source link

Support passing `--srcdir` to goimports #79

Open dbarnett opened 7 years ago

dbarnett commented 7 years ago

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 commented 7 years ago

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 commented 3 years ago

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 commented 3 years ago

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/.