Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goimports functionality #145

Closed
mitranim opened this issue Sep 8, 2021 · 3 comments
Closed

goimports functionality #145

mitranim opened this issue Sep 8, 2021 · 3 comments

Comments

@mitranim
Copy link

mitranim commented Sep 8, 2021

Currently using goimports. Would prefer gofumpt for stricter fmting, but the lack of automatic import editing is a show-stopper. Any chance this could be integrated?

@mvdan
Copy link
Owner

mvdan commented Sep 8, 2021

See #75. This tool does not aim to replace goimports. You can use both at the same time.

This question and confusion keeps coming up, so I'll keep this issue open as a reminder to add a FAQ entry.

@mitranim
Copy link
Author

mitranim commented Sep 8, 2021

That's unfortunate. Using both is more complicated and slower than using one. I use goimports via on-save. Piping the output of goimports to gofumpt requires an additional subprocess. While the bottleneck is goimports and gofumpt is probably reasonably quick, it complicates the setup (editor plugin needs to support multiple subprocesses, or the command must be a shell script involving |) and adds subprocess latency. I'll look into gopls as suggested in the issue you linked, but there are various downsides to using an LSP. If the user wants only formatting, using an LSP is like shooting a fly with a bazooka.

@mvdan
Copy link
Owner

mvdan commented Sep 8, 2021

Remember that using goimports as a tool will always be slow. It has to load a lot of information from disk and/or the network, especially to guess what package/module is missing.

So, if you want to be efficient with fixing imports, the answer is an LSP. Fixing imports is separate from formatting. If you don't want to use an LSP because performance isn't your top priority, then running goimports and gofumpt as separate tools will not add significant overhead.

@mvdan mvdan closed this as completed in 1727efe Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants