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

Autocompletion doesn't work for packages which were imported before saving the file #2179

Closed
nezorflame opened this issue Dec 7, 2018 · 3 comments
Labels
go-modules Related to Go modules upstream

Comments

@nezorflame
Copy link
Contributor

Continuing the discussion started in #1944 and #2164 in a new issue.

With "go.toolsEnvVars": { "GO111MODULE": "on" }, gocode-gomod is being launched now, which is good.
But, it still fails to give suggestions to the package functions before you save the file.

Prerequisits
Ext. version: 0.7.1-beta.5
OS: macOS 10.14.1
Latest vscode, Go 1.11.2, all Go tools updated through vscode-go.
Create simple main.go with empty main(), enable modules by go mod init.

Steps to reproduce:

  1. Action: Start writing fm
    Expect: fmt package should be suggested to be imported
    Result: success - got the suggestion:

default

  1. Action: Import fmt, write . to have function suggestions
    Expect: fmt package functions should be suggested
    Result: failure - nothing happens:

default

gocode-gomod -s -debug output (doubled for some reason?..):

2018/12/07 16:41:00 Got autocompletion request for '/Users/nezorflame/Go/src/test-project/main.go'
2018/12/07 16:41:00 Cursor at: 52
2018/12/07 16:41:00 -------------------------------------------------------
package main

import (
        "fmt"
)

func main() {
        fmt.#
}
2018/12/07 16:41:00 -------------------------------------------------------
2018/12/07 16:41:00 error in package test-project: /Users/nezorflame/Go/src/test-project/main.go:4:2:could not import fmt (no metadata for fmt)
2018/12/07 16:41:00 Elapsed duration: 103.788631ms
2018/12/07 16:41:00 Offset: 0
2018/12/07 16:41:00 Number of candidates found: 0
2018/12/07 16:41:00 Candidates are:
2018/12/07 16:41:00 =======================================================
2018/12/07 16:41:00 Got autocompletion request for '/Users/nezorflame/Go/src/test-project/main.go'
2018/12/07 16:41:00 Cursor at: 65
2018/12/07 16:41:00 -------------------------------------------------------
package main
import "fmt"

import (
        "fmt"
)

func main() {
        fmt.#
}
2018/12/07 16:41:00 -------------------------------------------------------
2018/12/07 16:41:00 error in package test-project: /Users/nezorflame/Go/src/test-project/main.go:2:8:could not import fmt (no metadata for fmt)
2018/12/07 16:41:00 error in package test-project: /Users/nezorflame/Go/src/test-project/main.go:5:2:fmt redeclared in this block
2018/12/07 16:41:00 error in package test-project: /Users/nezorflame/Go/src/test-project/main.go:2:8:    other declaration of fmt
2018/12/07 16:41:00 Elapsed duration: 98.44108ms
2018/12/07 16:41:00 Offset: 0
2018/12/07 16:41:00 Number of candidates found: 0
2018/12/07 16:41:00 Candidates are:
2018/12/07 16:41:00 =======================================================

But, if you save the file and try again, it will work this time!

  1. Action: Save the file, delete the . and insert it again:
    Expect: fmt package functions should be suggested
    Result: success - got the functions now:

default

@nezorflame nezorflame changed the title Autocompletion doesn't work for pacakges which were imported before saving the file Autocompletion doesn't work for packages which were imported before saving the file Dec 7, 2018
@ramya-rao-a
Copy link
Contributor

This is being tracked upstream in http://github.com/stamblerre/gocode/issues/3

@ramya-rao-a
Copy link
Contributor

@nezorflame The fix for this has been pushed in the upstream. Can you run the command Go: Install/Update Tools, choose gocode-gomod, press Ok to update it and try again?

@nezorflame
Copy link
Contributor Author

Yes, it works. Great job @stamblerre!

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
go-modules Related to Go modules upstream
Projects
None yet
Development

No branches or pull requests

2 participants