GoPLS Viewer

Home|gopls/internal/event/export/tag.go
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
5package export
6
7import (
8    "context"
9
10    "golang.org/x/tools/internal/event"
11    "golang.org/x/tools/internal/event/core"
12    "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.
20func Labels(output event.Exporterevent.Exporter {
21    return func(ctx context.Contextev core.Eventlm label.Mapcontext.Context {
22        stored_ := ctx.Value(labelContextKey).(label.Map)
23        if event.IsLabel(ev) || event.IsStart(ev) {
24            // update the label map stored in the context
25            fromEvent := label.Map(ev)
26            if stored == nil {
27                stored = fromEvent
28            } else {
29                stored = label.MergeMaps(fromEventstored)
30            }
31            ctx = context.WithValue(ctxlabelContextKeystored)
32        }
33        // add the stored label context to the label map
34        lm = label.MergeMaps(lmstored)
35        return output(ctxevlm)
36    }
37}
38
MembersX
Labels
Labels.output
Labels.BlockStmt.BlockStmt.fromEvent
Members
X