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

gopls: no autoimport, no autocomplete, no hover docs #2476

Closed
bitfield opened this issue Apr 26, 2019 · 13 comments
Closed

gopls: no autoimport, no autocomplete, no hover docs #2476

bitfield opened this issue Apr 26, 2019 · 13 comments

Comments

@bitfield
Copy link

Code Version 1.33.1 (1.33.1),
vscode-go 0.10.0

Steps to reproduce:

  1. Create a main.go file.
  2. Enter this code:
package main

func main() {
	os.Exit(1)
}
  1. Save

I would expect to see an automatic import "os" added, but it is not.

If I add it manually, I would expect to be able to hover over the os.Exit and see pop-up information about the function. I do not.

If I delete the Exit(1), place the cursor after os. and hit Ctrl-Space, I expect to see an auto-complete menu showing the available functions in os. Instead I see only the identifiers in the current file (func, import, main, and so on).

Settings as here: https://github.com/golang/go/wiki/gopls

gopls is running, as shown in the process list.

@detailyang
Copy link

same here 0.10.1 :(

@bitfield
Copy link
Author

To be honest, this support was intermittent and mostly not working before gopls, at least outside of GOPATH. To my knowledge the external tools used by vscode-go like goimports, go-guru and so on still do not fully support Go modules. It's hard to believe that gopls doesn't, though!

@detailyang
Copy link

Try the config and update the gopls go get -u golang.org/x/tools/cmd/gopls as the below:

"go.useLanguageServer": true,
"go.languageServerExperimentalFeatures": {
        "diagnostics": true // for diagnostics as you type
},
"[go]": {
    "editor.snippetSuggestions": "none",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
},
"gopls": {
    "usePlaceholders": true, // add parameter placeholders when completing a function
    "enhancedHover": true,   // experimental to improve quality of hover (will be on by default soon)
}

@stamblerre
Copy link
Contributor

Please let me know if you encounter more issues while using that config.
For the record, both goimports and gopls do support modules.

@bitfield
Copy link
Author

bitfield commented Apr 26, 2019

Upgrading to the latest gopls fixed the problem! [No it didn't. See below.]

What version of gopls does vscode-go install? Is it just always the latest available? Perhaps I was unlucky enough to update vscode-go at a moment when the latest gopls was broken. [No, this was a red herring. I just didn't have a go.mod file in the directory I was testing in.]

@bitfield
Copy link
Author

Hmm, scratch that: it works in some windows, not others. Reloading the window doesn't make any difference.

@bitfield
Copy link
Author

Specifically, it does not work if a go.mod file is present in the package.

  1. Create a new directory
  2. Create a main.go file containing the test code.
  3. Save the file. import "os" will be auto-added.
  4. Delete the import "os" line.
  5. Run go mod init tmp.
  6. Save the file. No auto-imports will be added, no formatting happens, hover and autocomplete no longer work.

@stamblerre
Copy link
Contributor

gopls does work with modules, but perhaps you encountered an issue that we haven't yet seen. Please file an issue here with some additional information, such as the contents of the file you are testing with.

@bitfield
Copy link
Author

Thanks @stamblerre, done!

@divmgl
Copy link

divmgl commented Apr 30, 2019

I'm having this problem still. No autocomplete at all with gopls. I'm on version 1.12 and I'm using go.mod in most of my project files. This was working previously with go-langserver I believe.

@bitfield
Copy link
Author

bitfield commented May 1, 2019

@divmgl hop over to golang/go#31712 😄

@gdoctor
Copy link

gdoctor commented May 1, 2019

I enabled gopls.. and quite literally nothing works. Not a single feature of vscode-go. I don't know what else to say. I completely reinstalled vscode and it's showing the same behavior.

Edit: Maybe this is known behavior.. I migrated a project from using dep to go modules for dependency management. My project contained a sub-project that, for the moment, I was unable to pull using 'go get' since it was on a private VCS (bitbucket), and I hadn't set up my ssh access key yet. Seemingly due to this fact, vscode-go was rendered entirely non-functioning up until the point I added the access key in bitbucket. Very strange behavior in my opinion.

@stamblerre
Copy link
Contributor

@gdoctor: thanks for the update - please file an issue here if you see anything else.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 11, 2019
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

5 participants