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

Autocomplete Should Complete From Packages Which Haven't Been Imported Yet #407

Closed
a-h opened this issue Jul 26, 2016 · 6 comments
Closed

Comments

@a-h
Copy link

a-h commented Jul 26, 2016

Just thinking how vscode-go could be even more awesome for me.

I sometimes find myself hunting through APIs. For example...

  • I know that in the fmt package, there is a function called Prints which formats to a string, but I can't remember the parameters.
  • So, I type fmt.Prints(, but I don't see any autocompletion. This is because fmt hasn't been imported yet.
  • I hit save, but it still doesn't import the package. I wonder why...
  • I put a value into the method's parameters and hit save, but it still doesn't add the import automatically.
  • I google the docs for the fmt package and realise that the function is actually called Sprint not Prints, so I fix it and hit save... the plugin now imports fmt and I can browse the parameters and return value in the popup.

I wanted to use vscode-go to help me browse the fmt package and choose the correct method, but it's not helping me to do that. Note how when I've typed fmt. I can't see anything...

autocomplete

It would be better if:

  • I type fmt. and a list of possible functions and their parent packages appears. fmt is already in my path (but not listed in my imports), so all the methods from fmt are listed. I notice Prints isn't in the list.
  • I notice that fmt.Sprint is there, I hit the down arrow a couple of times to choose it and press the open bracket. I'm in the parameters list, and I can see the popup detailing the parameters the method accepts.
  • I hit Save and the import statement is updated as usual.

Does anyone else think this would be good?

@leaxoy
Copy link
Contributor

leaxoy commented Jul 28, 2016

+1

@apognu
Copy link

apognu commented Jul 28, 2016

This is an issue most editors I've used suffer from. It would be amazing is this could be implemented.

@a-h
Copy link
Author

a-h commented Jul 28, 2016

Visual Studio (not VS Code) solves this problem in C# by adding a blue 'tag' to a type that can be imported, as well as by providing autocomplete for namespaces.

Hitting the blue tag provides a selection of assemblies which contain a MailMessage type, when one is selected then a using statement is added (similar to importing a package in Go).

Here's what it looks like in LinqPad:

visualstudio

(In the screencast, I've used the mouse to click on the little bar instead of the keyboard shortcut to make it clearer.)

@ramya-rao-a
Copy link
Contributor

This feature is now available in the latest version of the Go extension : 0.6.44

You need to set go.autocompleteUnimportedPackages to true to enable this feature.

Do give it a try and give feedback

We will turn it on by default in the next update

@a-h
Copy link
Author

a-h commented Nov 30, 2016

@ramya-rao-a - I'd just like to say thanks for implementing this feature, I've really been enjoying it!

@ramya-rao-a
Copy link
Contributor

@a-h Thanks for bringing up the feature request in the first place. There has been a lot of positive feedback around this!

@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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants