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

Closed
MatteoGioioso opened this issue Sep 21, 2019 · 9 comments
Closed
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

@MatteoGioioso
Copy link

MatteoGioioso 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 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 Sep 22, 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.

@MatteoGioioso
Copy link
Author

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
Copy link
Contributor

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

@stamblerre
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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

@stamblerre stamblerre added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 17, 2019
@stamblerre
Copy link
Contributor

@MatteoGioioso: Just wanted to follow up here - are you still experiencing this issue?

@MatteoGioioso
Copy link
Author

@stamblerre Unfortunately I am still experiencing this issue. However I have no problem with the development.

@golang golang locked and limited conversation to collaborators Oct 18, 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

4 participants