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: undeclared name error for name declared in different file #34440

Open
MatteoGioioso opened this issue Sep 21, 2019 · 7 comments

Comments

@MatteoGioioso
Copy link

commented Sep 21, 2019

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

$ go version
go version go1.13 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/madeo/.cache/go-build"
GOENV="/home/madeo/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/madeo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build233636058=/tmp/go-build -gno-record-gcc-switches"

What did you do?

VSCode

1.38.1
b37e54c98e1a74ba89e03073e5a3761284e3ffb0
x64

Ubuntu: 18.04.3 LTS

customer.go

package main

import "fmt"

// Customer customer object
type Customer struct {
	FirstName string
	LastName  string
}

func (c Customer) getFullName() string {
	return fmt.Sprintf("%s %s", c.FirstName, c.LastName)
}

main.go

package main

import (
	"fmt"
)

func main() {
	customer := Customer{"Some", "Name"}
	fullName := customer.getFullName()
	fmt.Println(fullName)
}

When I try to troubleshoot and I run: gopls -rpc.trace -v check /path/to/file.go
I receive gopls command not found, I then try to install gopls by running: GO111MODULE=on go get golang.org/x/tools/gopls@latest, and the output is: go: finding golang.org/x/tools latest and then it exits.
After restarting the terminal I still get gopls command not found

I have restarted my editor several times and also I have restarted languageServer

What did you expect to see?

Nothing since running the application produce no error

What did you see instead?

undeclared name: Customer

@ianlancetaylor ianlancetaylor changed the title undeclared name x/tools/gopls: undeclared name error for name declared in different file Sep 22, 2019
@gopherbot gopherbot added this to the Unreleased milestone Sep 22, 2019
@gopherbot

This comment has been minimized.

Copy link

commented Sep 22, 2019

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.

@MatteoGioioso

This comment has been minimized.

Copy link
Author

commented Sep 22, 2019

Ok after reading this: https://golang.org/doc/code.html, I have realized that I was doing everything wrong.
So now I have setup correctly my GOPATH and my projects are all under that path.

Though I still cannot find gopls

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2019

To get gopls, go get -u golang.org/x/tools/cmd/gopls.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Sep 25, 2019

To get gopls, go get -u golang.org/x/tools/cmd/gopls.

Actually, to install gopls you should run GO111MODULE=on go get golang.org/x/tools/gopls. It sounds like your $GOPATH/bin isn't on your PATH. Does running $GOPATH/bin/gopls check work?

@MatteoGioioso

This comment has been minimized.

Copy link
Author

commented Oct 3, 2019

running $GOPATH/bin/gopls check does not output anything, but yea the only way to run gopls is to ./gopls so that means that is not in my path, but the /bin actually is there.

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2019

You will want to move gopls into your $GOPATH/bin in order to use it through your editor - your editor will expect gopls to either be on your PATH or your GOPATH. If you have your GOPATH configured correctly, the command I suggested above will install gopls to $GOPATH/bin.

@MatteoGioioso

This comment has been minimized.

Copy link
Author

commented Oct 4, 2019

gopls is already in my GOPATH/bin. I will try to remove it and install it again. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.