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: doesn't recognize => token in go.mod #46246

Closed
RayfenWindspear opened this issue May 18, 2021 · 5 comments
Closed

x/tools/gopls: doesn't recognize => token in go.mod #46246

RayfenWindspear opened this issue May 18, 2021 · 5 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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@RayfenWindspear
Copy link

RayfenWindspear commented May 18, 2021

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

$ go version
go version go1.15.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes

$ gopls version
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

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

go env Output ($HOME path redacted to ~. Proprietary workspace path redacted to [redacted])
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="~/Library/Caches/go-build"
GOENV="~/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="~/go/pkg/mod"
GONOPROXY="*/plz-out/*"
GONOSUMDB="*/plz-out/*"
GOOS="darwin"
GOPATH="~/go"
GOPRIVATE="*/plz-out/*"
GOPROXY="file://~/go/src,file://~/go/src/[redacted]/plz-out/go/src,https://proxy.golang.org,direct"
GOROOT="~/go/src/[redacted]/plz-out/bin/third_party/go/toolchain"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="~/go/src/[redacted]/plz-out/bin/third_party/go/toolchain/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="~/go/src/[redacted]/go.mod"
CGO_CFLAGS="-march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe"
CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_q/7rwgffjn7p5d0x6tshsjkrjc0000gq/T/go-build194722657=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Added a replace directive to main workspace go.mod file.

replace github.com/apache/thrift v0.13.0 => github.com/apache/thrift/lib/go/thrift v0.0.0-20210120171102-e27e82c46ba4

What did you expect to see?

gopls handling this properly.

What did you see instead?

gopls doesn't parse the go.mod file correctly. It doesn't recognize => as valid tokens despite Go Modules specification clearly outlining the usage and grammar for the replace directive. https://golang.org/ref/mod#go-mod-file-replace


[Error - 3:42:26 PM] 2021/05/18 15:42:26 code lens upgrade_dependency failed: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"

[Error - 3:42:26 PM] 2021/05/18 15:42:26 code lens vendor failed: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"

[Error - 3:42:26 PM] 2021/05/18 15:42:26 code lens tidy failed: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"

[Error - 3:42:26 PM] 2021/05/18 15:42:26 errors loading workspace: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"
	snapshot=21
	directory=file://~/go/src/[redacted]

[Error - 3:42:27 PM] 2021/05/18 15:42:27 diagnosing go.mod: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"

[Error - 3:42:27 PM] 2021/05/18 15:42:27 diagnosing go.mod: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"

[Error - 3:42:27 PM] 2021/05/18 15:42:27 errors loading workspace: ~/go/src/[redacted]/go.mod:139: unexpected token after version: "v0.13.0"
	snapshot=22
	directory=file://~/go/src/[redacted]
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label May 18, 2021
@seankhliao seankhliao changed the title Modules replace directive => tokens unsupported by gopls go.mod parser. x/tools/gopls: doesn't recognize => token in go.mod May 18, 2021
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 18, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 18, 2021
@findleyr
Copy link
Contributor

findleyr commented May 19, 2021

Gopls supports =>, and in fact has a replace in its own modfile. Also, per my reading of the error the unexpected token is "v0.13.0".

That error is present in the go command, related to retraction, though not at 1.15.11. It's also present in x/mod (again for the retract verb), but I don't think an error from x/mod would present as the critical error you see.

Is it possible you typed 'retract' instead of 'replace'? Is it possible you have multiple versions of Go installed on your computer? Thanks.

@RayfenWindspear
Copy link
Author

I pasted it here exactly as it appears in go.mod, namely

replace github.com/apache/thrift v0.13.0 => github.com/apache/thrift/lib/go/thrift v0.0.0-20210120171102-e27e82c46ba4

So it's definitely replace. To be fair, I left a comment on that repo's commit and got the response that the particular commit is actually in an invalid state and he instructed me to use the next commit, which negated the need to even use replace. So my issue is technically solved, but this issue for gopls still results in the reported error state.

If it is supported as you claim, then I suppose it might somehow be related to the invalid go.mod state of the repo in question, but the errors thrown by gopls itself are still questionable. The replace resolved the errors issued by the regular go commands, but resulted in these errors here.

@findleyr
Copy link
Contributor

I suppose it might somehow be related to the invalid go.mod state of the repo in question

The error indicates the local go.mod, and the go.mod in github.com/apache/thrift/lib/go/thrift at that version is empty.

Gopls uses the same modfile parser as the go command: golang.org/x/mod. The error you see is either originating from executions of the go command, or from calls to x/mod from gopls. When I looked for it, it appears that its only occurrence is related to module retraction (linked above). Something strange is going on.

Just as a sanity check, I did create a minimal module that uses that exact replace directive. Everything works fine.

> cat go.mod
module mod.test

go 1.12

require github.com/apache/thrift v0.13.0

replace github.com/apache/thrift v0.13.0 => github.com/apache/thrift/lib/go/thrift v0.0.0-20210120171102-e27e82c46ba4
> cat main.go
package main

import "github.com/apache/thrift"

func main() {
        println(thrift.UNKNOWN_APPLICATION_EXCEPTION)
}

So I suspect there is something else in your go.mod file that is contributing to the error you see. Would you be able to provide a redacted version of your go.mod file, or try trimming down your modfile to a minimal repro? Could you also search the start of your logs for "go version", and make sure it agrees with the version you see on the command-line (go1.15.11)? I'd like to understand what's going on -- at the very least this is a confusing error message.

@RayfenWindspear
Copy link
Author

RayfenWindspear commented May 19, 2021

at the very least this is a confusing error message.

This was my argument for not dismissing this off-hand. I'll provide the full go.mod when I get back to work tomorrow.

The ultimate cause is possibly due to this being a massive monorepo using please.build for a build system, which ultimately does all it's individual builds in GOPATH mode. Despite that, as far as I'm aware, gopls should be pulling in the go.mod and initializing based off that. Perhaps that assumption is my failing...

I tried to be sure there weren't any queries being sent to the gopls server yet though, so the error occurs during initialization. If my assumptions there are false, then our repo itself could be at fault.

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 19, 2021
@findleyr
Copy link
Contributor

findleyr commented Jun 7, 2021

Hi, I'm closing this as unactionable for now. Please re-open if you are able to gather more details. Thanks.

@findleyr findleyr closed this as completed Jun 7, 2021
@stamblerre stamblerre removed this from the gopls/unplanned milestone Jun 7, 2021
@golang golang locked and limited conversation to collaborators Jun 7, 2022
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants