From 8d98c809a229b360e71ae5c3340be214f9039ab9 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Wed, 10 Jul 2019 21:11:23 -0400 Subject: [PATCH] internal/lsp: stop making background contexts everywhere For all uses inside the lsp we use the detatch logic instead For tests we build it in the test harness instead This is in preparation for things on the context becomming important Change-Id: I7e6910e0d3581b82abbeeb09f9c22a99efb73142 Reviewed-on: https://go-review.googlesource.com/c/tools/+/185677 Run-TryBot: Ian Cottrell Reviewed-by: Rebecca Stambler --- internal/xcontext/xcontext.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 internal/xcontext/xcontext.go diff --git a/internal/xcontext/xcontext.go b/internal/xcontext/xcontext.go new file mode 100644 index 0000000..b5c82f7 --- /dev/null +++ b/internal/xcontext/xcontext.go @@ -0,0 +1,23 @@ +// Copyright 2019 The Go MCP SDK Authors. All rights reserved. +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. + +// Package xcontext is a package to offer the extra functionality we need +// from contexts that is not available from the standard context package. +package xcontext + +import ( + "context" + "time" +) + +// Detach returns a context that keeps all the values of its parent context +// but detaches from the cancellation and error handling. +func Detach(ctx context.Context) context.Context { return detachedContext{ctx} } + +type detachedContext struct{ parent context.Context } + +func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false } +func (v detachedContext) Done() <-chan struct{} { return nil } +func (v detachedContext) Err() error { return nil } +func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) }