From d5449c00d2e9158aa8f4e5a0899dc417552f3a6b Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Mon, 24 May 2021 15:28:41 -0400 Subject: [PATCH] internal/lsp: fix mod file codelens The two codelenses that are attached to the module statement are 'Run go mod tidy' and 'Create vendor directory'. In a 'go.mod' file without any required modules, the only codelens that shows up is the 'Create vendor directory'. With no required modules, there is nothing to vendor, but 'Run go mod tidy' may actually clean up the go.mod and go.sum, so this is the codelens we want to appear. Change-Id: I7264f8c4c4427a66264684f71fd4407b2170609f Reviewed-on: https://go-review.googlesource.com/c/tools/+/322292 Trust: Suzy Mueller Run-TryBot: Suzy Mueller gopls-CI: kokoro Reviewed-by: Rebecca Stambler --- internal/lsp/mod/code_lens.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/lsp/mod/code_lens.go b/internal/lsp/mod/code_lens.go index d7310c7b7b..f18aaf7442 100644 --- a/internal/lsp/mod/code_lens.go +++ b/internal/lsp/mod/code_lens.go @@ -81,10 +81,6 @@ func tidyLens(ctx context.Context, snapshot source.Snapshot, fh source.FileHandl if err != nil || pm.File == nil { return nil, err } - if len(pm.File.Require) == 0 { - // Nothing to vendor. - return nil, nil - } uri := protocol.URIFromSpanURI(fh.URI()) cmd, err := command.NewTidyCommand("Run go mod tidy", command.URIArgs{URIs: []protocol.DocumentURI{uri}}) if err != nil { @@ -105,6 +101,10 @@ func vendorLens(ctx context.Context, snapshot source.Snapshot, fh source.FileHan if err != nil || pm.File == nil { return nil, err } + if len(pm.File.Require) == 0 { + // Nothing to vendor. + return nil, nil + } rng, err := moduleStmtRange(fh, pm) if err != nil { return nil, err