-
Notifications
You must be signed in to change notification settings - Fork 645
Format removes imports of vendored packages in use #613
Comments
For me it's It's really annoying. |
It works with |
Can you run |
I have tried running |
Can you share your settings? |
I tried the below code and I get build errors(
|
My settings don't have anything Go-related except Most, if not all, tools for Go (including Go differentiates between the last element of import path and package name. For |
I created a small example: https://github.com/AlekSi/vscode-bug |
Previously, the formatting tool ( As a means to fix that I had made the change to use Until the next update, as a workaround can you use @sindrepm |
Thanks for the update. I am pretty sure my issue is the same as @AlekSi mentions. It can very easily be reproduce with this simplified code: package main
import "github.com/xanzy/go-gitlab"
func main() {
c := gitlab.Client{}
} Try saving this file and the import line is removed. I do have Your workaround by changing |
@sindrepm Great, the pkg is a vendor pkg for you too. The next update (mostly end of this week), should have the fix |
The latest update of the Go extension (0.6.50) has the fix for this. |
Unfortunately, it doesn't work. Please try with https://github.com/AlekSi/vscode-bug. |
Sorry, nevermind, that one is another issue (#623). |
@sirianni can you try setting "go.formatTool" to "goimports"? |
Setting |
Same here. |
Yes, we moved to passing the file contents to the formatting tool instead of having the tool work on the file on disk. When doing so gofmt and goimports work well, but goreturns has issues with vendor pkgs and global variables that conflict with methods from other pkgs The same issue existed in goimports before, but is now fixed. I have logged an issue for goreturns to use the same fix. sqs/goreturns#40 Until that issue is fixed, use goimports |
I have the same issue which guide me to here. I think it should be reopened until the issue solved. |
@xyi The fix needs to be done upstream in the
|
Re-opening this issue, so that as soon as we have the upstream issue fixed, the Go extension should be updated to pass the |
This fix is now out in the latest update to the Go extension (0.6.71) |
I have installed 0.6.73 and still happening. I uninstalled it in order to continue coding |
@quetool Uninstalled what? Can you run |
@ramya-rao-a uninstalled the Go extension. I do not have these is my bug (it's my twitter account) https://twitter.com/quetool/status/951539146056749057 |
@quetool Is the package that is getting deleted used elsewhere in the code? Formatting removes unused imports. |
@ramya-rao-a Yes, is used in some functions to send messages to slack. This is what you are asking? |
Can you update all the dependent Go tools and try again? You can run the command |
That makes no sense to remove unused imports quietly, instead, if it could be a warning. |
Missing ">" , the command should be ">Go: Install/Update Tools" |
This issue still happening on 1.19.3(macOS), it's really really annoying for daily work, "goimports"/"goreturns" both don't work for me, any new fix? |
@Newt0n Did you try updating the tools as suggested in #613 (comment)? |
VSCode Version 1.19.3 |
@ramya-rao-a Yes, I've tried Seems like
|
@Newt0n The toolset to update is based on your config. (https://github.com/Microsoft/vscode-go/blob/d0c5309dd7f32689410e6f946245856c469ccc81/src/goInstallTools.ts#L90-L93) |
I just upgraded to the latest version and discovered a bug. When I have imports like the following:
Whenever I save the file, those import lines are removed even if they are referenced in the code. This has worked fine up until the last upgrade so not sure what has happened. From what I have found, it only applies to packages which contains a hyphen as shown above (e.g. "go-gitlab" and "go-restful").
I have been able to reference these packages just by the "gitlab" or "restful" names before, but now it seems that the goimports tool doesn't like that? If I alias the imports with "gitlab" or "restful" it works and the lines are not removed.
It is quite an annoying bug so hopefully this can be fixed.
The text was updated successfully, but these errors were encountered: