Skip to content

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

Open
@walles

Description

@walles

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

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Feb 27, 2023
added this to the Unreleased milestone on Feb 27, 2023
added
FeatureRequestIssues asking for a new feature that does not need a proposal.
on Mar 1, 2023
findleyr

findleyr commented on Mar 2, 2023

@findleyr
Member

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

walles

walles commented on May 6, 2023

@walles
Author

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

findleyr commented on May 10, 2023

@findleyr
Member

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

findleyr commented on May 11, 2023

@findleyr
Member

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @walles@gopherbot@findleyr

        Issue actions

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