1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:04:43 -07:00
go/internal/lsp/protocol/context.go
Rebecca Stambler 44a64ad78b internal/lsp, go/packages: don't log context cancellation errors
Instead of checking the context, check the error. This may expose some
errors that are not wrapped correctly. Replaced all uses of errors
with golang.org/x/xerrors.

Change-Id: Ia40160f8ea352e02618765f2a9415a4ece0dcd94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227036
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-03 19:08:13 +00:00

36 lines
695 B
Go

package protocol
import (
"context"
"fmt"
"golang.org/x/tools/internal/telemetry/event"
"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 event.Event, tags event.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 event.Err.Get(tags) != nil {
msg.Type = Error
}
go client.LogMessage(xcontext.Detach(ctx), msg)
return ctx
}