diff --git a/gopls/internal/regtest/bench/bench_test.go b/gopls/internal/regtest/bench/bench_test.go index 0801ecf753..360e9563c9 100644 --- a/gopls/internal/regtest/bench/bench_test.go +++ b/gopls/internal/regtest/bench/bench_test.go @@ -7,6 +7,8 @@ package bench import ( "flag" "fmt" + "os" + "runtime/pprof" "testing" "time" @@ -131,8 +133,9 @@ func TestBenchmarkSymbols(t *testing.T) { } var ( - benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.") - benchFile = flag.String("didchange_file", "", "The file to modify") + benchDir = flag.String("didchange_dir", "", "If set, run benchmarks in this dir. Must also set regtest_bench_file.") + benchFile = flag.String("didchange_file", "", "The file to modify") + benchProfile = flag.String("didchange_cpuprof", "", "file to write cpu profiling data to") ) // TestBenchmarkDidChange benchmarks modifications of a single file by making @@ -162,6 +165,17 @@ func TestBenchmarkDidChange(t *testing.T) { // Insert the text we'll be modifying at the top of the file. env.EditBuffer(*benchFile, fake.Edit{Text: "// __REGTEST_PLACEHOLDER_0__\n"}) result := testing.Benchmark(func(b *testing.B) { + if *benchProfile != "" { + profile, err := os.Create(*benchProfile) + if err != nil { + t.Fatal(err) + } + defer profile.Close() + if err := pprof.StartCPUProfile(profile); err != nil { + t.Fatal(err) + } + defer pprof.StopCPUProfile() + } b.ResetTimer() for i := 0; i < b.N; i++ { env.EditBuffer(*benchFile, fake.Edit{ diff --git a/internal/lsp/fake/sandbox.go b/internal/lsp/fake/sandbox.go index 34f1ba180c..f628f2d540 100644 --- a/internal/lsp/fake/sandbox.go +++ b/internal/lsp/fake/sandbox.go @@ -163,7 +163,7 @@ func UnpackTxt(txt string) map[string][]byte { } func validateConfig(config SandboxConfig) error { - if filepath.IsAbs(config.Workdir) && (config.Files != nil || config.InGoPath) { + if filepath.IsAbs(config.Workdir) && (len(config.Files) > 0 || config.InGoPath) { return errors.New("absolute Workdir cannot be set in conjunction with Files or InGoPath") } if config.Workdir != "" && config.InGoPath {