-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use new 'goimport' tool instead of VimScript for :GoImport and :GoDrop #1559
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1559 +/- ##
=========================================
+ Coverage 14.8% 15.8% +0.99%
=========================================
Files 53 53
Lines 4153 4055 -98
=========================================
+ Hits 615 641 +26
+ Misses 3538 3414 -124
Continue to review full report at Codecov.
|
Okay, finished up the loose ends and this seems to work well now. |
I maintained the current commands for compatibility btw, but we could remove |
Using the AST is going to fail when the go file is not yet parseable; e.g. if someone is in the middle of editing it and they
Given that |
Not exactly; we pass the |
Albeit less people use this because of goimports, I still think this is valuable. I'm +1 on this
I don't think this should show an error, instead it should be a noop. Just like :GoFmt, :GoAddTags, etc.. |
@Carpetsmoker testing reveals
And if it will remove the package declaration if run in
|
I haven't tested it yet, but I definitely want to make sure this works with build tags before merging. |
https://github.com/Carpetsmoker/goimport Fixes #1534 and deals with various other edge cases too.
I fixed the panic; I'm not 100% sure what you mean with "And if it will remove the package declaration if run in"; is that related to the panic or another issue? It works fine with build tags, as it operates on files rather than packages. I added a test for it to make sure. |
It's related to another issue. When the file does not have an import statement, I was seeing the |
Oh right; that should be fixed too now. |
I found another scenario where this fails. I created two new tests: refs/pull/1559/head...bhcleek:pr-1559/more-tests The |
@Carpetsmoker Martin, what's the state of this? Let us know how you feel about this. |
Instead of a large regexp-based VimScript to parse imports,
it now uses
goimport
, which parses the ast.Fixes #1534 and deals with various other edge cases too. The behaviour is mostly the same, except in cases where it didn't make too much sense to keep the old behaviour.
For example,
:GoImport errors
will now error out iferrors
is already imported, and:GoImport github.com/pkg/errors
will now replace any existingerrors
package instead of just adding it (this is actually the reason I started on this, because it's pretty annoying otherwise).