blob: 7e9246d89abd52e7133f1a435c7ae0aba7193398 [file] [log] [blame]
package protocol
import (
"context"
"fmt"
"golang.org/x/tools/internal/telemetry"
"golang.org/x/tools/internal/xcontext"
)
type contextKey int
const (
clientKey = contextKey(iota)
)
func WithClient(ctx context.Context, client Client) context.Context {
return context.WithValue(ctx, clientKey, client)
}
func LogEvent(ctx context.Context, event telemetry.Event) {
client, ok := ctx.Value(clientKey).(Client)
if !ok {
return
}
msg := &LogMessageParams{Type: Info, Message: fmt.Sprint(event)}
if event.Error != nil {
msg.Type = Error
}
go client.LogMessage(xcontext.Detach(ctx), msg)
}