Skip to content

x/tools/gopls: code action to organize imports blocking #41969

Closed
@myitcv

Description

@myitcv

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

$ go version
go version devel +aacbd7c3aa Thu Sep 24 09:15:20 2020 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20201009162240-fcf82128ed91
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20201009162240-fcf82128ed91

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/.vim/plugged/govim/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build112124304=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I don't have a specific repro per se, just noting per a conversation on #gopls-dev an apparent change in behaviour.

The crux of the issue is that a code action call to organize imports takes "a long time" where before it did not. In govim we trigger this as part of a blocking pre-save routine, hence a change in this behaviour is easily noticeable.

"Long time" might be anything up to 20 seconds, but more commonly is around 3 seconds. Whilst not long in the context of the history of the universe, in the context of a blocking UI call it feels like an age 😄

This appears to be most easily triggered by refactoring code in, say, a test file, where a reference t to a *testing.T is moved out of scope of the declaration of t, thereby triggering the organize imports code to try and resolve a package for the qualified identifier t.

Notes on what I've observed so far:

  • this appears to be made worse by larger projects, i.e. with larger dependency sets
  • this problem is particularly bad after a machine restart
  • closing Vim (and govim) and re-opening causes a longer delay (3 secs) compared to re-saving post an initial save (200ms) despite the fact I am using a remote LSP setup where the remote instance is not destroyed after the last client closes

What did you expect to see?

(Based on my understanding of how things should work following the last major "refactor")

No increased execution time of the organize imports code action call. It should return an answer based on the currently available cached package data.

Periodically, the goimports cache should be refreshed async from any LSP client calls.

What did you see instead?

Per above

cc @muirdm based on the report from Slack where you also saw this behaviour.


cc @stamblerre

FYI @leitzler

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions