1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:04:52 -07:00
go/internal/lsp/protocol/context.go
Ian Cottrell cf0cb92717 internal/telemetry: renaming to internal/event
internal/telemetry/event was renamed to internal/event/core
Some things were partly moved from internal/telemetry/event straight to
internal/event to minimize churn in the following restructuring.

Change-Id: I8511241c68d2d05f64c52dbe04748086dd325158
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229237
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-23 17:20:48 +00:00

36 lines
687 B
Go

package protocol
import (
"context"
"fmt"
"golang.org/x/tools/internal/event/core"
"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, ev core.Event, tags core.TagMap) context.Context {
if !ev.IsLog() {
return ctx
}
client, ok := ctx.Value(clientKey).(Client)
if !ok {
return ctx
}
msg := &LogMessageParams{Type: Info, Message: fmt.Sprint(ev)}
if core.Err.Get(tags) != nil {
msg.Type = Error
}
go client.LogMessage(xcontext.Detach(ctx), msg)
return ctx
}