lots of 'undeclared name' errors with vscode/gopls

6,374 views
Skip to first unread message

Xiangdong JI

unread,
Sep 27, 2019, 1:21:35 AM9/27/19
to golang-nuts
Hi,

I got a lot of 'undeclared name' errors with vscode, not sure it's something wrong with vscode or gopls, or my settings, hopefully someone can shed a light here, thanks.

Take src/runtime/mbitmap.go as an example, seems that any cross-file reference is not recognized, tried to run 'gopls check mbitmap.go' in terminal and got the same output,
the first few lines of gopls' output:

2019/09/27 05:16:28 Info:2019/09/27 05:16:28 96.267909ms for GOROOT= GOPATH=/home/xiaji01/.go GO111MODULE= PWD=/mnt/share/homes/xiaji01/src/go.svc/src/runtime go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go", stderr: <<>>
2019/09/27 05:16:28 Info:2019/09/27 05:16:28 go/packages.Load
        packages = 1
2019/09/27 05:16:28 Info:2019/09/27 05:16:28 go/packages.Load
        package = command-line-arguments
        files = [/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go]
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:150:29-41: undeclared name: heapAddrBits
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:150:43-57: undeclared name: heapArenaBytes
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:168:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:177:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:195:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:246:10-15: undeclared name: mspan


$ gopls version
    h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=

$ go version
go version devel +20f0bcb0c1 Sun Sep 22 17:10:30 2019 +0000 linux/amd64


Capture.JPG


MUNGAI NJOROGE

unread,
Sep 27, 2019, 2:50:11 AM9/27/19
to Xiangdong JI, golang-nuts
Hi, had the same issue when using Go modules. Does your project have modules?

Also, check GOPATH and GROOT setting. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d4000ccd-cb3d-4e8e-b2cf-6391311ce836%40googlegroups.com.

MUNGAI NJOROGE

unread,
Sep 27, 2019, 2:50:11 AM9/27/19
to Xiangdong JI, golang-nuts
Meant GOROOT 

Xiangdong JI

unread,
Sep 27, 2019, 3:28:49 AM9/27/19
to golang-nuts
Thanks for the hint.

My vscode project is built on Go source code tree, turns out gopls, the project (go compiler source) and go binary should be 
version compatible, I solved the problem by setting the source code path as GOROOT in settings.json and rebuild the extension tools.

On Friday, September 27, 2019 at 2:50:11 PM UTC+8, MUNGAI wrote:
Hi, had the same issue when using Go modules. Does your project have modules?

Also, check GOPATH and GROOT setting. 

On Fri, Sep 27, 2019, 8:21 AM Xiangdong JI <xiang...@arm.com> wrote:
Hi,

I got a lot of 'undeclared name' errors with vscode, not sure it's something wrong with vscode or gopls, or my settings, hopefully someone can shed a light here, thanks.

Take src/runtime/mbitmap.go as an example, seems that any cross-file reference is not recognized, tried to run 'gopls check mbitmap.go' in terminal and got the same output,
the first few lines of gopls' output:

2019/09/27 05:16:28 Info:2019/09/27 05:16:28 96.267909ms for GOROOT= GOPATH=/home/xiaji01/.go GO111MODULE= PWD=/mnt/share/homes/xiaji01/src/go.svc/src/runtime go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go", stderr: <<>>
2019/09/27 05:16:28 Info:2019/09/27 05:16:28 go/packages.Load
        packages = 1
2019/09/27 05:16:28 Info:2019/09/27 05:16:28 go/packages.Load
        package = command-line-arguments
        files = [/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go]
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:150:29-41: undeclared name: heapAddrBits
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:150:43-57: undeclared name: heapArenaBytes
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:168:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:177:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:195:10-15: undeclared name: mspan
/mnt/share/homes/xiaji01/src/go.svc/src/runtime/mbitmap.go:246:10-15: undeclared name: mspan


$ gopls version
    h1:YwKf8t9h69++qCtVmc2q6fVuetFXmmu9LKoPMYLZid4=

$ go version
go version devel +20f0bcb0c1 Sun Sep 22 17:10:30 2019 +0000 linux/amd64


Capture.JPG


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.

JuciÊ Andrade

unread,
Sep 29, 2019, 12:14:19 PM9/29/19
to golang-nuts
Gopls depends on finding a go.mod file, otherwise you get lots of "undeclared name".
If it's not there just go to your project root folder and issue the command "go mod init".

Reply all
Reply to author
Forward
0 new messages