| 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package exportscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export`/ |
| 6 | |
| 7 | import ( |
| 8 | "contextscip-go gomod github.com/golang/go/src go1.25.0 context/" |
| 9 | |
| 10 | "golang.org/x/tools/internal/eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/" |
| 11 | "golang.org/x/tools/internal/event/corescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/" |
| 12 | "golang.org/x/tools/internal/event/labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/" |
| 13 | ) |
| 14 | |
| 15 | // Labels builds an exporter that manipulates the context using the event. |
| 16 | // If the event is type IsLabel or IsStartSpan then it returns a context updated |
| 17 | // with label values from the event. |
| 18 | // For all other event types the event labels will be updated with values from the |
| 19 | // context if they are missing. |
| 20 | func Labelsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export`/Labels().(output eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/.Exporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/Exporter#) eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/.Exporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/Exporter# { |
| 21 | return func(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#, ev corescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/.Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#, lm labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Mapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Map#) contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context# { |
| 22 | stored, _ := ctx.Valuescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Value().(labelContextKeyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export`/labelContextKey.).(labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Mapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Map#) |
| 23 | if eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/.IsLabelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/IsLabel().(ev) || eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/.IsStartscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event`/IsStart().(ev) { |
| 24 | // update the label map stored in the context |
| 25 | fromEvent := labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Mapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Map#(ev) |
| 26 | if stored == nil { |
| 27 | stored = fromEvent |
| 28 | } else { |
| 29 | stored = labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.MergeMapsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/MergeMaps().(fromEvent, stored) |
| 30 | } |
| 31 | ctx = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.0 context/WithValue().(ctx, labelContextKeyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export`/labelContextKey., stored) |
| 32 | } |
| 33 | // add the stored label context to the label map |
| 34 | lm = labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.MergeMapsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/MergeMaps().(lm, stored) |
| 35 | return output(ctx, ev, lm) |
| 36 | } |
| 37 | } |