1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "golang.org/x/tools/internal/event"
12 "golang.org/x/tools/internal/event/core"
13 "golang.org/x/tools/internal/event/export"
14 "golang.org/x/tools/internal/event/label"
15 "golang.org/x/tools/internal/xcontext"
21 clientKey = contextKey(iota)
24 func WithClient(ctx context.Context, client Client) context.Context {
25 return context.WithValue(ctx, clientKey, client)
28 func LogEvent(ctx context.Context, ev core.Event, lm label.Map, mt MessageType) context.Context {
29 client, ok := ctx.Value(clientKey).(Client)
33 buf := &bytes.Buffer{}
35 p.WriteEvent(buf, ev, lm)
36 msg := &LogMessageParams{Type: mt, Message: buf.String()}
37 // Handle messages generated via event.Error, which won't have a level Label.
38 if event.IsError(ev) {
41 go client.LogMessage(xcontext.Detach(ctx), msg)