Skip to content

Commit 5b06639

Browse files
committed
internal/lsp/source: only show "run file benchmarks" if available
We were previously showing them even if there were no benchmarks to run. Fixes golang/go#43239 Change-Id: I51d1de12e86009cca6d8ea41208949ed01484f6a Reviewed-on: https://go-review.googlesource.com/c/tools/+/278780 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 11a5667 commit 5b06639

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

internal/lsp/source/code_lens.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,29 @@ func runTestCodeLens(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p
7171
})
7272
}
7373

74-
_, pgf, err := GetParsedFile(ctx, snapshot, fh, WidestPackage)
75-
if err != nil {
76-
return nil, err
77-
}
78-
// add a code lens to the top of the file which runs all benchmarks in the file
79-
rng, err := NewMappedRange(snapshot.FileSet(), pgf.Mapper, pgf.File.Package, pgf.File.Package).Range()
80-
if err != nil {
81-
return nil, err
82-
}
83-
args, err := MarshalArgs(fh.URI(), []string{}, fns.Benchmarks)
84-
if err != nil {
85-
return nil, err
74+
if len(fns.Benchmarks) > 0 {
75+
_, pgf, err := GetParsedFile(ctx, snapshot, fh, WidestPackage)
76+
if err != nil {
77+
return nil, err
78+
}
79+
// add a code lens to the top of the file which runs all benchmarks in the file
80+
rng, err := NewMappedRange(snapshot.FileSet(), pgf.Mapper, pgf.File.Package, pgf.File.Package).Range()
81+
if err != nil {
82+
return nil, err
83+
}
84+
args, err := MarshalArgs(fh.URI(), []string{}, fns.Benchmarks)
85+
if err != nil {
86+
return nil, err
87+
}
88+
codeLens = append(codeLens, protocol.CodeLens{
89+
Range: rng,
90+
Command: protocol.Command{
91+
Title: "run file benchmarks",
92+
Command: CommandTest.ID(),
93+
Arguments: args,
94+
},
95+
})
8696
}
87-
codeLens = append(codeLens, protocol.CodeLens{
88-
Range: rng,
89-
Command: protocol.Command{
90-
Title: "run file benchmarks",
91-
Command: CommandTest.ID(),
92-
Arguments: args,
93-
},
94-
})
9597
return codeLens, nil
9698
}
9799

0 commit comments

Comments
 (0)