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: go.mod: Please provide completions for package versions #58769

Open
walles opened this issue Feb 27, 2023 · 4 comments
Open

x/tools/gopls: go.mod: Please provide completions for package versions #58769

walles opened this issue Feb 27, 2023 · 4 comments
Labels
FeatureRequest 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

@walles
Copy link

walles commented Feb 27, 2023

gopls version

~/s/g/gopls (master|✔) $ gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
    golang.org/x/exp/typeparams@v0.0.0-20221031165847-c99f073a8326 h1:fl8k2zg28yA23264d82M4dp+YlJ3ngDcpuB1bewkQi4=
    golang.org/x/mod@v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
    golang.org/x/sync@v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
    golang.org/x/sys@v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
    golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
    golang.org/x/tools@v0.3.1-0.20221213193459-ca17b2c27ca8 h1:7/HkGkN/2ktghBCSRRgp31wAww4syfsW52tj7yirjWk=
    golang.org/x/vuln@v0.0.0-20221109205719-3af8368ee4fe h1:qptQiQwEpETwDiz85LKtChqif9xhVkAm8Nhxs0xnTww=
    honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.20.1
~/s/g/gopls (master|✔) $

go env

~/s/moar (master|✔) $ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johan/Library/Caches/go-build"
GOENV="/Users/johan/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/johan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/johan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.20.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.20.1/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/johan/src/moar/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cg/d7qzk4s13s9c8t49t3txdjpr0000gn/T/go-build4241905905=/tmp/go-build -gno-record-gcc-switches -fno-common"
~/s/moar (master|✔) $

What did you do?

Typing in this go.mod file.

On the github.com/sirupsen/logrus line, I deleted v1.8.1 and typed just a v instead.

module github.com/walles/moar

go 1.16

require (
	github.com/alecthomas/chroma/v2 v2.4.0
	github.com/google/go-cmp v0.5.9
	github.com/sirupsen/logrus v1.8.1
	golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744
	golang.org/x/term v0.0.0-20210503060354-a79de5458b56
	gotest.tools/v3 v3.3.0
)

What did you expect to see?

Version number completions:

  • v1.9.0 (latest version as I'm typing in this issue)

What did you see instead?

No completion, just the v that I typed.

Editor and settings

vscode.json:

{
  "go.useLanguageServer": true,
  "go.toolsManagement.autoUpdate": true,
  "go.lintTool": "golangci-lint"
}

Logs

@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 Feb 27, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 27, 2023
@findleyr
Copy link
Contributor

findleyr commented Mar 2, 2023

I agree, this would be nice. Thank you for the suggestion.

@findleyr findleyr modified the milestones: Unreleased, gopls/later Mar 2, 2023
@walles
Copy link
Author

walles commented May 6, 2023

Two questions on how to test this:

  1. I tried to make a test file like this one but with a require line like mvdan.cc/xurls v1. //@complete(re"v1.", "v1.1.0"), diag("v1.", re"must be of the form v1.2.3").

    However, it seems like the testing framework doesn't want to load incomplete go.mod files. Is this correct? What would be the easiest way to make a go.mod completions test?

  2. Is there a way of faking go list -m -versions output for a module while testing? I want to avoid having the tests break suddenly because some maintainer decides to publish a new version of some package?

@findleyr
Copy link
Contributor

Hi @walles answers below:

  1. I'll try this out; even if gopls cannot load go files, it should still provide support for editing go.mod files. We should enable this workflow. However, in the meantime you should be able leave the go.mod file in a valid state (ie.g. with mvdan.cc/xurls v1.0.0 and still trigger completion at re"v1."
  2. Not in the "marker" tests, yet. For other regression tests, we use a fake proxy. See an example here. It's a pain, because you must have the correct go.sum content. I have been meaning to make the new marker tests support this with better ergonomics. If you want to wait, I can do this.

@findleyr
Copy link
Contributor

@walles the marker tests now support proxy files. See https://go.dev/cl/494396 for examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest 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

3 participants