mdempsky / gocode

An autocompletion daemon for the Go programming language
MIT License
906 stars 87 forks source link

Intellisense not working for imported packages when using dep #101

Closed fabianem closed 4 years ago

fabianem commented 5 years ago

Setup

I am using: OS: windows 10 vs code: 1.30.1 go version: go1.11.4 windows/amd64 (and go1.11.1 linux/amd64 on WSL)

go env on windows:

PS C:\Users\fab> go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\fab\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\go-dev
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\fab\AppData\Local\Temp\go-build706593530=/tmp/go-build -gno-record-gcc-switches

go env on WSL (ubuntu):

fab@fab-surfacePro:/mnt/c/go-dev/src/mc2innovations.visualstudio.com/CP_BC_Chaincodes$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fab/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/mnt/c/go-dev"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build893031043=/tmp/go-build -gno-record-gcc-switches"

Problem

Continuing issue #https://github.com/Microsoft/vscode-go/issues/2182

tl;dr: While using dep I am not receiving any intellisense for imported packages.

local packages:

2019/01/08 16:33:32 Got autocompletion request for 'c:\go-dev\src\mc2innovations.visualstudio.com\CP_BC_Chaincodes\testPkg\test.go'
2019/01/08 16:33:32 Cursor at: 219
2019/01/08 16:33:32 -------------------------------------------------------
package testPkg
import "mc2innovations.visualstudio.com/CP_BC_Chaincodes/tokenUtils"

import (
        "mc2innovations.visualstudio.com/CP_BC_Chaincodes/tokenUtils"
        "fmt"
)

func main() {
        fmt.Println("testing")

        tokenUtils.#
}
2019/01/08 16:33:32 -------------------------------------------------------
2019/01/08 16:33:32 Error parsing input file (outer block):
2019/01/08 16:33:32  c:\go-dev\src\mc2innovations.visualstudio.com\CP_BC_Chaincodes\testPkg\test.go:12:13: expected selector or type assertion, found ';'
2019/01/08 16:33:32 Elapsed duration: 6ms
2019/01/08 16:33:32 Offset: 0
2019/01/08 16:33:32 Number of candidates found: 0
2019/01/08 16:33:32 Candidates are:
2019/01/08 16:33:32 =======================================================

external packages:

2019/01/08 16:31:55 Got autocompletion request for 'c:\go-dev\src\mc2innovations.visualstudio.com\CP_BC_Chaincodes\testPkg\test.go'
2019/01/08 16:31:55 Cursor at: 256
2019/01/08 16:31:55 -------------------------------------------------------
package testPkg
import "github.com/hyperledger/fabric/core/chaincode/shim"

import (
        "github.com/hyperledger/fabric/core/chaincode/shim"
        "mc2innovations.visualstudio.com/CP_BC_Chaincodes/tokenUtils"
        "fmt"
)

func main() {
        fmt.Println("testing")

        shim.#
}
2019/01/08 16:31:55 -------------------------------------------------------
2019/01/08 16:31:55 Error parsing input file (outer block):
2019/01/08 16:31:55  c:\go-dev\src\mc2innovations.visualstudio.com\CP_BC_Chaincodes\testPkg\test.go:13:7: expected selector or type assertion, found ';'
2019/01/08 16:31:55 Elapsed duration: 10.982ms
2019/01/08 16:31:55 Offset: 0
2019/01/08 16:31:55 Number of candidates found: 0
2019/01/08 16:31:55 Candidates are:
2019/01/08 16:31:55 =======================================================

But after inserting the function manually, peek for definition works fine: image

Also all necessary .a files exist:

for windows_amd64:

fab@fab-surfacePro:/mnt/c/go-dev/pkg/windows_amd64/mc2innovations.visualstudio.com$ find CP_BC_Chaincodes/ -maxdepth 1
CP_BC_Chaincodes/
CP_BC_Chaincodes/errorUtils.a
CP_BC_Chaincodes/eventUtils.a
CP_BC_Chaincodes/loggerUtils.a
CP_BC_Chaincodes/tokenUtils.a
CP_BC_Chaincodes/validatorUtils.a
CP_BC_Chaincodes/vendor

for linux_amd64:

fab@fab-surfacePro:/mnt/c/go-dev/pkg/linux_amd64/mc2innovations.visualstudio.com$ find CP_BC_Chaincodes/ -maxdepth 1
CP_BC_Chaincodes/
CP_BC_Chaincodes/errorUtils.a
CP_BC_Chaincodes/eventUtils.a
CP_BC_Chaincodes/loggerUtils.a
CP_BC_Chaincodes/tokenUtils.a
CP_BC_Chaincodes/validatorUtils.a
CP_BC_Chaincodes/vendor

And just to understand it better I would like to ask again: When running vs code on windows, vs code is using GOPATH/bin/gocode.exe, right? And does gocode.exe searches only for the .a files in GOPATH/pkg/windows_amd64 or also in GOPATH/pkg/linux_amd64?

stamblerre commented 5 years ago

Yes, on Windows, VSCode-Go runs the executable $GOPATH/bin/gocode.exe, but that's just because that's how executables are named on Windows. I believe that if you run go install for gocode on Windows, gocode.exe will be built.

Also, gocode only looks in the $GOPATH/pkg folder for the architecture that you are on. So on, Windows, it will be $GOPATH/pkg/windows_amd64, and on Ubuntu, it will be $GOPATH/pkg/linux_amd64. Just to check, which architecture is the problem occurring on - both? What flags, if any, are you passing into gocode?

fabianem commented 5 years ago

Also, gocode only looks in the $GOPATH/pkg folder for the architecture that you are on. So on, Windows, it will be $GOPATH/pkg/windows_amd64, and on Ubuntu, it will be $GOPATH/pkg/linux_amd64.

Ok thx for the explanation. I feared so because thats what led me to the problem with building \github.com\miekg\pkcs11 on windows. Which is kinda difficult because I need to get libtools working on windows - but I will think about this later :)

Just to check, which architecture is the problem occurring on - both?

Actually I tried it only on windows because thats where I run VScode. Ubuntu I use only as WSL on windows - so no gui here. Do you know of another option how I could try this on ubuntu wsl?

What flags, if any, are you passing into gocode?

I left all by default, so I guess I am passing none. But how could I verify this when using gocode in VScode?

stamblerre commented 4 years ago

Closing this issue, as this repository is in maintenance mode. For a better Go autocompletion experience, I would suggest using gopls.

It also seems that https://github.com/mdempsky/gocode/issues/84 would be relevant here.