Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / internal / lsp / protocol / context.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/internal/lsp/protocol/context.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/internal/lsp/protocol/context.go
new file mode 100644 (file)
index 0000000..5a87dd2
--- /dev/null
@@ -0,0 +1,41 @@
+package protocol
+
+import (
+       "bytes"
+       "context"
+
+       "golang.org/x/tools/internal/event"
+       "golang.org/x/tools/internal/event/core"
+       "golang.org/x/tools/internal/event/export"
+       "golang.org/x/tools/internal/event/label"
+       "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 label.Map) context.Context {
+       if !event.IsLog(ev) {
+               return ctx
+       }
+       client, ok := ctx.Value(clientKey).(Client)
+       if !ok {
+               return ctx
+       }
+       buf := &bytes.Buffer{}
+       p := export.Printer{}
+       p.WriteEvent(buf, ev, tags)
+       msg := &LogMessageParams{Type: Info, Message: buf.String()}
+       if event.IsError(ev) {
+               msg.Type = Error
+       }
+       go client.LogMessage(xcontext.Detach(ctx), msg)
+       return ctx
+}