learnlytics-go/templ/lsp/protocol/context.go

27 lines
569 B
Go
Raw Permalink Normal View History

2025-03-20 12:35:13 +01:00
// SPDX-FileCopyrightText: 2020 The Go Language Server Authors
// SPDX-License-Identifier: BSD-3-Clause
package protocol
import (
"context"
)
type ctxClientKey int
var ctxClient ctxClientKey = 0
// WithClient returns the context with Client value.
func WithClient(ctx context.Context, client Client) context.Context {
return context.WithValue(ctx, ctxClient, client)
}
// ClientFromContext extracts Client from context.
func ClientFromContext(ctx context.Context) Client {
client, ok := ctx.Value(ctxClient).(Client)
if !ok {
return nil
}
return client
}