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

Autocomplete and Go: Add Import broken when working with SubPackages #521

Closed
sethgrid opened this issue Oct 11, 2016 · 9 comments
Closed

Comments

@sethgrid
Copy link

I created a very simple example here:
https://github.com/sethgrid/vscode_autocomplete_issue

Basically, when working with subpackages (from one to another, or from the root to a subpackage), there is no autocomplete and you cannot find the subpackage with > Go: Add Import.

@sethgrid
Copy link
Author

note: you can mouse over the non-autocompleted methods and see their signature. Information is making its way over, but functionality is missing.

@ramya-rao-a
Copy link
Contributor

@sethgrid Does autocomplete work for you for other external packages?
Autocomplete is provided by gocode which has had issues with go 1.7
The below is from the ReadMe for the Go extension

Important Note: If you have recently upgraded to Go 1.7, you may need to run gocode close in your terminal to ensure Go completion lists continue to work correctly. See #441.

Go: Add Import internally uses gopkgs to get the list of pkgs that can be imported.
Can you run gopkgs in your command line and see if you are seeing your sub packages?
gopkgs looks for packages in your $GOPATH/pkg.

@sethgrid
Copy link
Author

@ramya-rao-a autocomplete / > Go: Add Import works for other external packages, yes. I did have to update gocode back when I moved to Go 1.7 (thanks for verifying!).

I just ran gopkgs (neat, I did not know about that), and it does not see the subpackages, so that is likely the source of the problem. Looking at https://github.com/tpng/gopkgs, I see they strive for a faster go list all. I do see my subpackages with go list all.

If you clone the simple example repo, were you able to reproduce the issue?

I opened an issue for gopkgs here: tpng/gopkgs#4

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Oct 12, 2016

Well, then it might be because the packages are not being generated. That is why gopkgs is not able to see them, but go list all is able to.

I cloned your repo and I am able to get autocomplete and Add Import on the sub packages

Can you check your $GOPATH/pkg/<platform-specific-folder>/github.com/sethgrid/vscode_autocomplete_issue folder? Is it empty?

Can you share your customized settings (User and Workspace)?

@sethgrid
Copy link
Author

sethgrid commented Oct 12, 2016

When I check out the pkg dir, it is missing vscode_autocomplete_issue.

$ ls /Users/sethammons/workspace/go/pkg/darwin_amd64/github.com/sethgrid/

That lists some *.a files that match packages that do show up with gopkgs. Maybe this has to do with how I create new projects? I tend to cd over to a given directory in my GOPATH, mkdir and then touch the files I'll need. I expected that to "just work." Knowing that we are working with the pkg dir, I did a go install in the example repo and, tada, autocomplete works. Removing the pkg files and doing it again with go get (inside the problem directory), I see that the pkg files show up too.

It feels odd to have to have built or otherwise gotten your system to generate data in the pkg dir to get autocomplete. That seems to hamper initial development until you either run go install or go get in your directory. Now that I know I can fix the issue when I see it with go get, maybe it is a non issue, but it would be nice to not have to do that (it would be nice if things showed up from the src dir, not just the pkg dir). Thanks for helping dig into this!

In case it is still of interest:
User Settings:

// Place your settings in this file to overwrite the default settings
{
    "go.buildOnSave": false,
    "go.lintOnSave": true,
    "go.vetOnSave": true,
    "go.buildTags": "",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.useCodeSnippetsOnFunctionSuggest": false,
    "go.formatOnSave": true,
    "go.formatTool": "goreturns",
    "go.goroot": "/usr/local/go",
    "go.gopath": "/Users/sethammons/workspace/go",
    "go.gocodeAutoBuild": false,
    "files.associations": {"*.tmpl": "html"}
}

And the workspace settings are empty:

// Place your settings in this file to overwrite default and user settings.
{
}

@sethgrid
Copy link
Author

sethgrid commented Oct 12, 2016

With running go get in the affected dir (or go install) getting autocomplete to work, do you feel this issue is closed, or do you see value in some edge case handling for working with packages being developed that are not yet in the pkg dir? And, again, a super big thank you for helping me through this! It is very appreciated.

@tpng
Copy link

tpng commented Oct 12, 2016

You can change the setting "go.gocodeAutoBuild": false to "go.gocodeAutoBuild": true to skip the go get or go install step.

@ramya-rao-a
Copy link
Contributor

@tpng is right. Below is a note from the README for the Go extension:

This extension uses gocode to provide completion lists as you type. To provide fresh results, including against not-yet-built dependencies, the extension uses gocode's autobuild=true setting. If you experience any performance issues with autocomplete, you should try setting "go.gocodeAutoBuild": false in your VS Code settings.

@sethgrid
Copy link
Author

Awesome, good to know. Thanks for all the help and for providing a great tool.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 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

3 participants