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

Autocomplete is missing after using gocode-gomod #2148

Closed
avence12 opened this issue Nov 26, 2018 · 12 comments
Closed

Autocomplete is missing after using gocode-gomod #2148

avence12 opened this issue Nov 26, 2018 · 12 comments

Comments

@avence12
Copy link

avence12 commented Nov 26, 2018

I used solutions of https://github.com/ikgo/gocode and https://github.com/ikgo/gopkgs for my Go Module projects since Oct. and everything goes well.
After upgrade to latest vscode-go and all dependencies of go tools, autocomplete is missing on std/import/local libraries even from scratch.

Information:

  • MacOS Mojave 10.14.1
  • go version go1.11.1 darwin/amd64
  • vscode 1.29.1
  • vscode-go 0.7.1-beta.1 without any user/workspace settings

Steps to Reproduce:

  1. Create an empty folder outside of GOPATH
  2. go mod init golang-example
  3. gocode-gomod close ; gocode-gomod -s -debug to enable debug mode
  4. Add some lines in main.go

image

  1. No candidates found every for fmt package

image

  1. The result of go list -json -compiled
{
	"Dir": "/tmp/golang-exmaple",
	"ImportPath": "golang-example",
	"Name": "main",
	"Target": "/Users/avence12/devel/gotools/bin/golang-example",
	"Module": {
		"Path": "golang-example",
		"Main": true,
		"Dir": "/tmp/golang-exmaple",
		"GoMod": "/tmp/golang-exmaple/go.mod"
	},
	"Match": [
		"."
	],
	"Stale": true,
	"StaleReason": "build ID mismatch",
	"GoFiles": [
		"main.go"
	],
	"CompiledGoFiles": [
		"main.go"
	],
	"Imports": [
		"fmt"
	],
	"Deps": [
		"errors",
		"fmt",
		"internal/bytealg",
		"internal/cpu",
		"internal/poll",
		"internal/race",
		"internal/syscall/unix",
		"internal/testlog",
		"io",
		"math",
		"math/bits",
		"os",
		"reflect",
		"runtime",
		"runtime/internal/atomic",
		"runtime/internal/sys",
		"strconv",
		"sync",
		"sync/atomic",
		"syscall",
		"time",
		"unicode",
		"unicode/utf8",
		"unsafe"
	]
}
  1. ls $GOPATH/bin

image

  1. go env
$ go env
GOARCH="amd64"
GOBIN="/Users/avence12/devel/opensource/gotools/bin"
GOCACHE="/Users/avence12/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/avence12/devel/opensource/gotools"
GOPROXY=""
GORACE=""
GOROOT="/Users/avence12/.gvm/gos/go1.11.1"
GOTMPDIR=""
GOTOOLDIR="/Users/avence12/.gvm/gos/go1.11.1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tx/y15w994j5cjg8r1nxh2704940000gn/T/go-build099303572=/tmp/go-build -gno-record-gcc-switches -fno-common"
@saibing
Copy link

saibing commented Nov 26, 2018

@avence12

bingo is a new go language server that support go 1.11 module.

you can try it.

@shaodahong
Copy link

shaodahong commented Nov 26, 2018

I have the same problem
if the current project has go.mod file, Autocomplete is fail

0² tree -L 1
.
├── go.mod
└── main.go

0 directories, 2 files
0² go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/shaodahong/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shaodahong/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/shaodahong/Workspace/demo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j3/1mmzgr1j51s_kgdg28ksn7b40000gn/T/go-build815312150=/tmp/go-build -gno-record-gcc-switches -fno-common"
0² go version
go version go1.11.2 darwin/amd64

image

@ramya-rao-a
Copy link
Contributor

cc @stamblerre

@stamblerre
Copy link
Contributor

@avence12: in your case, I notice that go env GOMOD is empty. Do you have GO111MODULE=on configured?

@shaodahong: I added some additional logging to gocode-gomod in stamblerre/gocode@02c18bb. Could you try syncing to head and pasting in the output of gocode-gomod -s -debug? Thanks!

@shaodahong
Copy link

@stamblerre

0² gocode-gomod -s -debug
2018/11/27 12:17:51 Got autocompletion request for '/Users/shaodahong/Workspace/demo/main.go'
2018/11/27 12:17:51 Cursor at: 49
2018/11/27 12:17:51 -------------------------------------------------------
package main

import (
	"fmt"
)

func main() {
	f#

}
2018/11/27 12:17:51 -------------------------------------------------------
2018/11/27 12:17:51 Elapsed duration: 214.123096ms
2018/11/27 12:17:51 Offset: 0
2018/11/27 12:17:51 Number of candidates found: 4
2018/11/27 12:17:51 Candidates are:
2018/11/27 12:17:51   const false untyped bool
2018/11/27 12:17:51   package fmt
2018/11/27 12:17:51   type float32 float32
2018/11/27 12:17:51   type float64 float64
2018/11/27 12:17:51 =======================================================
2018/11/27 12:17:52 Got autocompletion request for '/Users/shaodahong/Workspace/demo/main.go'
2018/11/27 12:17:52 Cursor at: 52
2018/11/27 12:17:52 -------------------------------------------------------
package main

import (
	"fmt"
)

func main() {
	fmt.#

}
2018/11/27 12:17:52 -------------------------------------------------------
2018/11/27 12:17:52 Elapsed duration: 177.578011ms
2018/11/27 12:17:52 Offset: 0
2018/11/27 12:17:52 Number of candidates found: 25
2018/11/27 12:17:52 Candidates are:
2018/11/27 12:17:52   func Errorf(format string, a ...interface{}) error
2018/11/27 12:17:52   func Fprint(w io.Writer, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Fprintln(w io.Writer, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Fscan(r io.Reader, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Fscanln(r io.Reader, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Print(a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Printf(format string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Println(a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Scan(a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Scanf(format string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Scanln(a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Sprint(a ...interface{}) string
2018/11/27 12:17:52   func Sprintf(format string, a ...interface{}) string
2018/11/27 12:17:52   func Sprintln(a ...interface{}) string
2018/11/27 12:17:52   func Sscan(str string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Sscanf(str string, format string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   func Sscanln(str string, a ...interface{}) (n int, err error)
2018/11/27 12:17:52   type Formatter interface
2018/11/27 12:17:52   type GoStringer interface
2018/11/27 12:17:52   type ScanState interface
2018/11/27 12:17:52   type Scanner interface
2018/11/27 12:17:52   type State interface
2018/11/27 12:17:52   type Stringer interface
2018/11/27 12:17:52 =======================================================

@stamblerre
Copy link
Contributor

@shaodahong: ok, so it seems like it's working for you actually. So I think your problem is probably the one being discussed on #1944, so let's move the discussion there.

@avence12
Copy link
Author

avence12 commented Nov 27, 2018

@stamblerre

I realize I posted go env result from out of my project folder. Just paste the correct one below.
I also have set my vscode workspace config with "go.toolsEnvVars": {"GO111MODULE": "on"}

$ go env
GOARCH="amd64"
GOBIN="/Users/avence12/devel/opensource/gotools/bin"
GOCACHE="/Users/avence12/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/avence12/devel/opensource/gotools"
GOPROXY=""
GORACE=""
GOROOT="/Users/avence12/.gvm/gos/go1.11.1"
GOTMPDIR=""
GOTOOLDIR="/Users/avence12/.gvm/gos/go1.11.1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/golang-exmaple/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tx/y15w994j5cjg8r1nxh2704940000gn/T/go-build481121418=/tmp/go-build -gno-record-gcc-switches -fno-common"

After upgrading to stamblerre/gocode@02c18bb, I can see some new information.

image

@stamblerre
Copy link
Contributor

@avence12: I don't think it should matter, but it's worth noting that you have a typo:

From your go list output: Your Dir is set to "/tmp/golang-exmaple", and the "ImportPath": "golang-example". Do you mind fixing it and trying again? I don't think it's the error, but worth checking. Thanks.

@avence12
Copy link
Author

avence12 commented Nov 28, 2018

@stamblerre

I have fixed the typo but no luck.

$ go list -json -compiled
{
        "Dir": "/private/tmp/golang-example",
        "ImportPath": "golang-example",
        "Name": "main",
        "Target": "/Users/avence12/devel/opensource/gotools/bin/golang-example",
        "Module": {
                "Path": "golang-example",
                "Main": true,
                "Dir": "/private/tmp/golang-example",
                "GoMod": "/private/tmp/golang-example/go.mod"
        },
        "Match": [
                "."
        ],
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "GoFiles": [
                "main.go"
        ],
        "CompiledGoFiles": [
                "main.go"
        ],
        "Imports": [
                "fmt"
        ],
        "Deps": [
                "errors",
                "fmt",
                "internal/bytealg",
                "internal/cpu",
                "internal/poll",
                "internal/race",
                "internal/syscall/unix",
                "internal/testlog",
                "io",
                "math",
                "math/bits",
                "os",
                "reflect",
                "runtime",
                "runtime/internal/atomic",
                "runtime/internal/sys",
                "strconv",
                "sync",
                "sync/atomic",
                "syscall",
                "time",
                "unicode",
                "unicode/utf8",
                "unsafe"
        ]
}

Results of gocode-gomod -s -debug. Look like it cannot find package.

2018/11/28 09:50:49 Got autocompletion request for '/private/tmp/golang-example/main.go'
2018/11/28 09:50:49 Cursor at: 65
2018/11/28 09:50:49 -------------------------------------------------------
package main
import "fmt"
import (
	"fmt"
)
func main() {
	fmt.#
}
2018/11/28 09:50:49 -------------------------------------------------------
2018/11/28 09:50:49 no package found for /private/tmp/golang-example/main.go: <nil>
2018/11/28 09:50:49 Elapsed duration: 58.209397ms
2018/11/28 09:50:49 Offset: 0
2018/11/28 09:50:49 Number of candidates found: 0
2018/11/28 09:50:49 Candidates are:
2018/11/28 09:50:49 =======================================================

My workspace settings:

{
  "go.buildFlags": [],
  "go.buildOnSave": "package",
  "go.buildTags": "",
  "go.coverOnSave": false,
  "go.docsTool": "gogetdoc",
  "go.enableCodeLens": {
    "references": false,
    "runtest": false
  },
  "go.formatTool": "gofmt",
  "go.gocodeAutoBuild": false,
  "go.lintFlags": [],
  "go.lintOnSave": "off",
  "go.lintTool": "golangci-lint",
  "go.testOnSave": false,
  "go.toolsEnvVars": {"GO111MODULE": "on"},
  "go.vetFlags": [],
  "go.vetOnSave": "off",
}

According to stamblerre/gocode@02c18bb, it did not throw error nor load any packages.

@stamblerre
Copy link
Contributor

can you try go list -json -compiled /private/tmp/golang-example?

@stamblerre
Copy link
Contributor

Also, I just made a small change, so if you can try syncing to head again, it might fix the issue. (Remember to run gocode-gomod close when you restart.)

@avence12
Copy link
Author

Autocomplete works well after using vscode-go 0.7.1-beta.2 and the latest fix on stamblerre/gocode@22843d8

Thanks for your awesome support.

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