Skip to content

Commit

Permalink
gopls/internal/server: simplify snapshot diagnostics
Browse files Browse the repository at this point in the history
Address a TODO by eliminating the server.diagnosePkgs method, which had
its own layer over concurrency. Instead, inline the logic as necessary
into the two places it was called, and merge the two WaitGroups.

In general, try to consolidate calls to server.storeDiagnostics, as a
subsequent CL will change the storage schema.

Also add some new utility packages for working with generics.

For golang/go#57979

Change-Id: Ia739f83deb97054b141c93ed8b9f6d5f54ee1d8b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/546017
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
Auto-Submit: Robert Findley <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Nov 30, 2023
1 parent 4058894 commit f48aac8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/event/keys/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package keys

import (
"sort"
"strings"
)

// Join returns a canonical join of the keys in S:
// a sorted comma-separated string list.
func Join[S ~[]T, T ~string](s S) string {
strs := make([]string, 0, len(s))
for _, v := range s {
strs = append(strs, string(v))
}
sort.Strings(strs)
return strings.Join(strs, ",")
}
29 changes: 29 additions & 0 deletions internal/event/keys/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package keys

import "testing"

func TestJoin(t *testing.T) {
type T string
type S []T

tests := []struct {
data S
want string
}{
{S{"a", "b", "c"}, "a,b,c"},
{S{"b", "a", "c"}, "a,b,c"},
{S{"c", "a", "b"}, "a,b,c"},
{nil, ""},
{S{}, ""},
}

for _, test := range tests {
if got := Join(test.data); got != test.want {
t.Errorf("Join(%v) = %q, want %q", test.data, got, test.want)
}
}
}

0 comments on commit f48aac8

Please sign in to comment.