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: unable to use workspace mode due to misuse of -mod flag #48186

Closed
mvdan opened this issue Sep 3, 2021 · 7 comments
Closed

x/tools/gopls: unable to use workspace mode due to misuse of -mod flag #48186

mvdan opened this issue Sep 3, 2021 · 7 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@mvdan
Copy link
Member

mvdan commented Sep 3, 2021

gopls @v0.0.0-20210902182115-3b801c8b8389
go version devel go1.18-ab7c904bf2 Fri Sep 3 05:27:58 2021 +0000 linux/amd64

I'm trying #45713; I've set up a fairly simple go.work file as follows:

go 1.18

directory (
	git/ipfs
	src/ipld
	src/multicodec
)

And I've hit "go to definition" in ipfs, which should take me to a file within the multicodec module. This works without the workspace file; it just takes me inside the module download cache.

However, it just errors:

Exception not caught: got error whilst handling command:GOVIMGoToDef: failed to call gopls.Definition: err: exit status 1: stderr: go: -mod may only be set to readonly when in workspace mode

It appears gopls is calling cmd/go with a -mod value other than "readonly" somewhere, which is not supported by workspace mode.

I'm happy to provide precise repro steps here, since all this code is open source after all, but I also imagine this is enough detail for you to figure out what you need.

cc @matloob @stamblerre

@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 3, 2021
@gopherbot gopherbot added this to the Unreleased milestone Sep 3, 2021
@mvdan
Copy link
Member Author

mvdan commented Sep 5, 2021

It's possible this is caused by govim, as per @leitzler on Slack:

This setting might be useful for you unless you have it set already: https://github.com/govim/govim/blob/61d4fa23afba84a51e9a88a81c721907261bd8cb/cmd/govim/config/config.go#L312

And @heschi then mentioned:

The setting Pontus linked to is totally unsupported in gopls, but on by default in govim.

@leitzler
Copy link
Contributor

leitzler commented Sep 5, 2021

It would be helpful with a repro from my point of view, I can give it a look into the govim side.
I haven't used go.work yet so it is unfamiliar territory. This simple example did work for me where I jump from b.B in a/a.go to b/b.go:

-- a/a.go --
package a

import "b"

const A = 2

func fn() {
	b.B
}
-- a/go.mod --
module a

go 1.18
-- b/b.go --
package b

const B = 1
-- b/go.mod --
module b

go 1.18
-- go.work --
go 1.17

directory (
    ./a
    ./b
)

I do however the setting I linked in my config (the default value is 1/true): (EDIT: it works without it as well)

call govim#config#Set("ExperimentalAllowModfileModifications", 0)

Also had to enable workspace modules using:

call govim#config#Set("ExperimentalWorkspaceModule", 1)

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 7, 2021
@findleyr findleyr modified the milestones: Unreleased, gopls/on-deck Sep 7, 2021
@findleyr
Copy link
Contributor

findleyr commented Sep 7, 2021

Thanks for the report.

@mvdan have you tried call govim#config#Set("ExperimentalAllowModfileModifications", 0)? Does that avoid the errors for you?

@mvdan
Copy link
Member Author

mvdan commented Sep 7, 2021

I haven't had more time to dig into this or try again :) I also did not enable workspace support in gopls via call govim#config#Set("ExperimentalWorkspaceModule", 1). I honestly assumed that gopls would just work out of the box with it, given that cmd/go from Go master now supports workspaces by default. If I still need to enable the feature in gopls, maybe the instructions in the proposal should be updated.

@findleyr
Copy link
Contributor

findleyr commented Sep 7, 2021

I honestly assumed that gopls would just work out of the box

Agreed, which is why I'm suspicious of this govim setting. I can investigate and try to repro, but it will probably take a few days for me to get to this. If it's easy for you try unsetting this experimental feature in govim, that would help narrow it down.

@gopherbot
Copy link

Change https://golang.org/cl/347593 mentions this issue: cmd/go: print offending -mod value in workspace mode

gopherbot pushed a commit that referenced this issue Sep 8, 2021
Workspace mode only allows -mod to be set to 'readonly'. When returning
the error for other values of -mod, specify the the value in the error
so it's easier to see what's going on when the go command is invoked
through another tool.

For #45713, #48186

Change-Id: I3ba206a71c7a20c18aeccfa48f3c9dc935a180a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/347593
Trust: Michael Matloob <matloob@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@mvdan
Copy link
Member Author

mvdan commented Sep 30, 2021

Ever since I disabled ExperimentalAllowModfileModifications, I haven't run into this error again. So I think the blame should indeed be put on that option being on when it shouldn't be. I've filed govim/govim#1112 to fix that in govim.

I think we can close this issue for now, unless others run into similar errors with gopls again (with that experimental setting turned off!).

@mvdan mvdan closed this as completed Sep 30, 2021
@stamblerre stamblerre removed this from the gopls/on-deck milestone Oct 11, 2021
leitzler added a commit to govim/govim that referenced this issue Feb 7, 2022
The previous default value for for the config setting
ExperimentalAllowModfileModifications was "true", which isn't the
default value for gopls.

Enabling this setting causes issues with the new workspace mode in
gopls as described in #1112 and referred golang/go#48186. It also seem
to cause issues in upcoming Go 1.18, see golang/go#51056.

Closes #1112
leitzler added a commit to govim/govim that referenced this issue Feb 7, 2022
The previous default value for for the config setting
ExperimentalAllowModfileModifications was "true", which isn't the
default value for gopls.

Enabling this setting causes issues with the new workspace mode in
gopls as described in #1112 and referred golang/go#48186. It also seem
to cause issues in upcoming Go 1.18, see golang/go#51056.

Closes #1112
leitzler added a commit to govim/govim that referenced this issue Feb 21, 2022
The previous default value for for the config setting
ExperimentalAllowModfileModifications was "true", which isn't the
default value for gopls.

Enabling this setting causes issues with the new workspace mode in
gopls as described in #1112 and referred golang/go#48186. It also seem
to cause issues in upcoming Go 1.18, see golang/go#51056.

Closes #1112
@golang golang locked and limited conversation to collaborators Oct 11, 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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants