Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Go Code is removing a proper import even after adding it #1266

Closed
selfup opened this issue Oct 6, 2017 · 5 comments
Closed

Go Code is removing a proper import even after adding it #1266

selfup opened this issue Oct 6, 2017 · 5 comments

Comments

@selfup
Copy link

selfup commented Oct 6, 2017

👋

Here is the repo I am using (to help us all figure out what is going on here): https://github.com/selfup/go-cache-http

Current workaround:

https://github.com/selfup/go-cache-http/blob/master/main.go#L8

Problem

There is a UI bug

So I have a lib directory at the root of my project.

I try to import it correctly: "github.com/package-name/lib"

And this tool just makes it disappear! Poof 💥 🚀

I am trying to just import the functions, not force myself to do:

import (
  lib "github.com/user/package-name/lib"
)

// and then do something like
func main() {
  lib.ExportedFunction()
}

I would prefer (since this is an internal library to the package) to do something like:

import (
  "github.com/user/package-name/lib"
)

// and then do something like
func main() {
  ExportedFunction()
}

if I am just doing something wrong please let me know

GIF showing what is happening

2017-10-05 19 40 15

I save my work, then it gets rid of it 😂

Conclusion

How am I supposed to import this while using this wonderful tool? 🤔

Unless of course this is convention pushed by the linter then I apologize in advance for all of this!


If this is indeed convention, the dropdown should auto match the ending dir name (possibly).

Ex: "github.com/user/package-name/foo" to auto make foo "github.com/user/package-name/foo" if this is going to be forced from a stylistic point of view 😄

@lggomez
Copy link
Contributor

lggomez commented Oct 9, 2017

I had a similar problem (in my case, adding undesired/wrong imports) and my workaround was to change the format tool to gofmt. This user setting should do the trick:

"go.formatTool": "gofmt"

@selfup
Copy link
Author

selfup commented Oct 9, 2017

Oh thanks I will try this out in a bit 😄

@ramya-rao-a
Copy link
Contributor

@selfup

I am trying to repro this.

  • Ran go get github.com/selfup/go-cache-http
  • Opened the go-cache-http folder in VS Code
  • Removed the lib "github.com/selfup/go-cache-http/lib" line from the import block in main.go file
  • Saved the file

Instead of getting the error on missing import, the missing import got added when I saved the file.
This is because the default formatting tool goreturns adds missing imports and removes unused imports.

Is there anything else I should have done to get a repro?

@selfup
Copy link
Author

selfup commented Oct 16, 2017

Yea I don't seem to be able to reproduce this anymore 😂

Sorry for the bother! The GIF captured the bad behavior but like you said, it seems to autofix now and is not reproducible.

Thanks for checking it out!

@selfup selfup closed this as completed Oct 16, 2017
@ramya-rao-a
Copy link
Contributor

No problem, Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants