Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: IDE shows undeclared name on every symbols when accessing from other files #34951

Closed
witoong623 opened this issue Oct 17, 2019 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@witoong623
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Hasegawa\AppData\Local\go-build
set GOENV=C:\Users\Hasegawa\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Hasegawa\Documents\goworkspace
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Hasegawa\AppData\Local\Temp\go-build045062746=/tmp/go-build -gno-record-gcc-switches

Setting from settings.json in VS Code

{
    "go.useLanguageServer": true,
    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true,
        }
    },
    "gopls": {
        "usePlaceholders": true, // add parameter placeholders when completing a function

        // Experimental settings
        "completeUnimported": true, // autocomplete unimported packages
        "watchFileChanges": true,  // watch file changes outside of the editor
        "deepCompletion": true,     // enable deep completion
    },
    "files.eol": "\n", // formatting only supports LF line endings
}

Out put from gopls version

golang.org/x/tools/gopls v0.1.7
    golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=

Out put from gopls -rpc.trace -v check /path/to/file.go

2019/10/17 17:20:18 Info:2019/10/17 17:20:18 Build info
----------
golang.org/x/tools/gopls v0.1.7
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Hasegawa\Documents\Taamkru\centurion\go.mod
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Hasegawa\AppData\Local\Temp\go-build041154958=/tmp/go-build -gno-record-gcc-switches       
2019/10/17 17:20:18 Info:2019/10/17 17:20:18 75.7964ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "env" "GOMOD", stderr: <<>> 
2019/10/17 17:20:18 Info:2019/10/17 17:20:18 116.6865ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>
2019/10/17 17:20:18 Info:2019/10/17 17:20:18 172.5412ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-m" "-json" "all", 
stderr: <<>>
2019/10/17 17:20:18 Info:2019/10/17 17:20:18 66.8211ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "env" "GOMOD", stderr: <<>> 
2019/10/17 17:20:18 Info:2019/10/17 17:20:18 141.6212ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-m" "-json" "all", 
stderr: <<>>
2019/10/17 17:20:29 Info:2019/10/17 17:20:29 10.7621978s for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "C:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal", stderr: <<>>
2019/10/17 17:20:29 Info:2019/10/17 17:20:29 399.9824ms for GOROOT= GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=C:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "C:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal\\daemon.go", stderr: <<>>
2019/10/17 17:20:29 Info:2019/10/17 17:20:29 go/packages.Load
        packages = 1
2019/10/17 17:20:29 Info:2019/10/17 17:20:29 go/packages.Load
        package = command-line-arguments
        files = [C:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go]
C:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go:18:15-24: undeclared name: Processor
C:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go:79:27-36: undeclared name: Processor
C:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go:79:45-54: undeclared name: AppConfig
C:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go:80:13-24: undeclared name: NewDatabase

gopls logs

[Info  - 16:56:36] 2019/10/17 16:56:36 Build info
----------
golang.org/x/tools/gopls v0.1.7
    golang.org/x/tools/gopls@v0.1.7 h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20190918214516-5a1a30219888 h1:ER45Jz0UDQ3e6em1lwXVwuPf96lvyQogb7m+gEbsoPg=
    golang.org/x/xerrors@v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

Go info
-------
go version go1.13 windows/amd64

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Hasegawa\AppData\Local\go-build
set GOENV=C:\Users\Hasegawa\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Hasegawa\Documents\goworkspace
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=c:\Users\Hasegawa\Documents\Taamkru\centurion\go.mod
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Hasegawa\AppData\Local\Temp\go-build229086746=/tmp/go-build -gno-record-gcc-switches

[Info  - 16:56:36] 2019/10/17 16:56:36 108.7157ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "env" "GOMOD", stderr: <<>>

[Info  - 16:56:36] 2019/10/17 16:56:36 181.5144ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "builtin", stderr: <<>>

[Info  - 16:56:36] 2019/10/17 16:56:36 255.3158ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-m" "-json" "all", stderr: <<>>

[Info  - 16:56:36] 2019/10/17 16:56:36 87.7871ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "env" "GOMOD", stderr: <<>>

[Info  - 16:56:36] 2019/10/17 16:56:36 164.5584ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-m" "-json" "all", stderr: <<>>

[Info  - 16:57:19] 2019/10/17 16:57:19 43.0087112s for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "c:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal", stderr: <<>>

[Info  - 16:57:20] 2019/10/17 16:57:20 414.716ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "c:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal\\daemon.go", stderr: <<>>

[Info  - 16:57:20] 2019/10/17 16:57:20 go/packages.Load
	packages = 1
[Info  - 16:57:20] 2019/10/17 16:57:20 go/packages.Load
	package = command-line-arguments
	files = [c:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go]
[Info  - 16:57:20] 2019/10/17 16:57:20 52.858ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "env" "GOMOD", stderr: <<>>

[Info  - 16:57:20] 2019/10/17 16:57:20 122.6712ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-m" "-json" "all", stderr: <<>>

[Info  - 16:57:30] 2019/10/17 16:57:30 10.5437931s for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "c:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal", stderr: <<>>

[Info  - 16:57:31] 2019/10/17 16:57:31 392.0388ms for GOROOT=c:\go GOPATH=C:\Users\Hasegawa\Documents\goworkspace GO111MODULE=on PWD=c:\Users\Hasegawa\Documents\Taamkru\centurion go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "c:\\Users\\Hasegawa\\Documents\\Taamkru\\centurion\\internal\\daemon.go", stderr: <<>>

[Info  - 16:57:31] 2019/10/17 16:57:31 go/packages.Load
	packages = 1
[Info  - 16:57:31] 2019/10/17 16:57:31 go/packages.Load
	package = command-line-arguments
	files = [c:\Users\Hasegawa\Documents\Taamkru\centurion\internal\daemon.go]

What did you do?

I am using project structure similar to this

cmd
    - exenamed
        - main.go
internal
    - firstfile.go
    - secondfile.go
    - thirdfile.go

and I access symbols from others file.

What did you expect to see?

I can access symbols from others file and VS Code does not show undeclared name.

What did you see instead?

VS Code complains on every symbols from others file undeclared name.

Additional Infomation

  • I can compile this code without problem.
@gopherbot gopherbot added this to the Unreleased milestone Oct 17, 2019
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 17, 2019
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre
Copy link
Contributor

When you opened the VSCode window, did you open it from the directory that contains the go.mod file?

@witoong623
Copy link
Author

@stamblerre Yes, I do. I have just solved my problem.

I tried run go mod tidy because I thought it could be a problem related to go mod file not sync or something (I thought go mod tidy is intended to be used for clean or sync go.mod file) and I found that there was a import statement in a test file that import the package that does not exist (because I refactored my project). After delete the import statement, everything work as expect again.

I am so sorry for posting this stupid question. I should have run the test.

@stamblerre
Copy link
Contributor

Not a problem! Thank you for following up!

@golang golang locked and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants