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: documentation, error messages, and mod tidy behavior can make adding a dependency confusing #60935

Open
p3tr0v opened this issue Jun 22, 2023 · 5 comments
Labels
gopls/metadata Issues related to metadata loading in gopls 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

@p3tr0v
Copy link

p3tr0v commented Jun 22, 2023

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

$ go version
go version go1.20.5 windows/amd64
go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user\AppData\Local\go-build
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\dev\projects\golang\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\dev\projects\golang
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\dev\Go\1.20.5
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\dev\Go\1.20.5\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.5
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\dev\projects\golang\src\projX\subProjX\go.mod
set GOWORK=C:\dev\projects\golang\src\go.work
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\user\AppData\Local\Temp\go-build1680866235=/tmp/go-build -gno-record-gcc-switches

What did you do?

I installed all my Go dev environment from zero, by Go 1.20
I set my GOPATH as env above, then I set my go.work file on the root from my workspace, like the official ref says to do.
After typing "go get github.com/any/module/example", the project are downloaded to GOMODCACHE but Golang says that "could not find the package", and I just ask "why???"
It really uncomfortable when you follow the official reference and this happen, seems that Google engineers don't understand how workspace and dependency works, and I really don't wanna believe on it.

What did you expect to see?

I expect see golang finding the packages after "go get"

What did you see instead?

Golang cant find the packages under his own structure.

@seankhliao
Copy link
Member

please show real commands and output

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 22, 2023
@p3tr0v
Copy link
Author

p3tr0v commented Jun 22, 2023

please show real commands and output
@seankhliao @Nasfame

Sure!
At first, my GOPATH is under C:\dev\projects\golang directory, not in my home user dir.
So I have this structure:

C:\dev\projects\golang
__________________\bin
__________________\pkg
__________________\src

Under C:\dev\projects\golang\src I have all my many projects and under some projects I have sub-projects. Besides I have go.work JUST under my root src dir.
For example:
C:\dev\projects\golang\src\go.work
C:\dev\projects\golang\src\clientA\project01 (under here I have .go files and go.mod)
C:\dev\projects\golang\src\clientA\project02 (under here I have .go files and go.mod)
C:\dev\projects\golang\src\clientB\project01 (under here I have .go files and go.mod)
C:\dev\projects\golang\src\myOtherProject (under here I have .go files and go.mod)

Whenever I create a new project I type go work use . , example:

cd C:\dev\projects\golang\src\clientA\project01
go work use .

Then inside go.work I have like this

go 1.20

use (
 ./clientA/project01
 ./clientA/project02
 ./clientB/project01
 ./myOtherProject
)

Now let's suppose I wanna add some Github module to my project "clientA\project01" to be used.
Then, under my GOPATH, I type (I use go install since go get is deprecated) :
go install github.com/bla/bla/bla

After this moment I realised that the repository github.com/bla/bla/bla is downloaded to C:\dev\projects\golang\pkg\mod not to C:\dev\projects\golang\src\github.com as I was imagining would be done.

Into my Go file where the module will be used, I set "github.com/bla/bla/bla" in imports.
Then I type (I don't understand for sure why I have to do it, I think I red at some tutorial after downloading a new module I have to tidy my project module)

cd C:\dev\projects\golang\src\clientA\project01
go mod tidy

I have the warning that this module "could not be find under GOROOT or GOPATH"!!!
I'm using VS Code IDE.

Please, Where am I doing wrong?? I spent many many many stressed hours trying to understand and fixing this issues when it comes about projects and modules management.

Thanks in advance

@p3tr0v p3tr0v closed this as completed Jun 22, 2023
@p3tr0v p3tr0v reopened this Jun 22, 2023
@p3tr0v p3tr0v closed this as completed Jun 22, 2023
@p3tr0v p3tr0v reopened this Jun 22, 2023
@p3tr0v p3tr0v closed this as completed Jun 22, 2023
@p3tr0v p3tr0v reopened this Jun 22, 2023
@p3tr0v p3tr0v closed this as completed Jun 22, 2023
@p3tr0v p3tr0v reopened this Jun 22, 2023
@seankhliao seankhliao changed the title Golang cant find packages on this own GOMODCACHE dir. x/tools/gopls: cant find packages on this own GOMODCACHE dir Jun 22, 2023
@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 Jun 22, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 22, 2023
@findleyr findleyr removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 26, 2023
@findleyr
Copy link
Contributor

findleyr commented Jul 6, 2023

Then, under my GOPATH, I type (I use go install since go get is deprecated

go get is not deprecated. It is used for getting dependencies and adding them to your go.mod file. The only aspect of go get that was deprecated is using it to download binaries.

go install does not modify your go.mod, which is probably why you are encountering this error message. go get is actually the correct command to use.

I understand your frustration with the documentation / tutorials.

@findleyr findleyr changed the title x/tools/gopls: cant find packages on this own GOMODCACHE dir x/tools/gopls: documentation, error messages, and mod tidy behavior can make adding a dependency confusing Jul 6, 2023
@findleyr
Copy link
Contributor

findleyr commented Jul 6, 2023

I have retitled this issue with what I think is the real problem: our documentation, tutorials, and behavior of gopls and the go command can make the simple act of adding a dependency confusing and error prone. I certainly think this is something we can and should fix. Please correct me if I am misrepresenting your experience.

I am putting this in the gopls@v0.13.0 milestone, as I think it falls into a broad category of onboarding, go command integration, and error messages that we're collecting into that release.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.13.0 Jul 6, 2023
@adonovan adonovan added the gopls/metadata Issues related to metadata loading in gopls label Aug 31, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.15.0 Oct 9, 2023
@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/metadata Issues related to metadata loading in gopls 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

6 participants
@adonovan @gopherbot @seankhliao @p3tr0v @findleyr and others