1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:08:33 -06:00
go/internal/lsp/cache/keys.go
Ian Cottrell 54cf04ef09 internal/lsp: decouple client and server debug
This uses log messages to convey information to the debug system, which
has the benefit of logging even if the debug pages are not active and
also not requiring systems to reach into the debug system or require
extra lifetime tracking Not all things are decoupled yet as there are a
couple of places (notably the handshaker) that read information out of
the debug system.

Change-Id: Iec1f81c34ab3b11b3e3d6e6eb39b98ee5ed0d849
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236337
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-11 13:49:48 +00:00

53 lines
1.5 KiB
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cache
import (
"io"
"golang.org/x/tools/internal/event/label"
)
var (
KeyCreateSession = NewSessionKey("create_session", "A new session was added")
KeyUpdateSession = NewSessionKey("update_session", "Updated information about a session")
KeyShutdownSession = NewSessionKey("shutdown_session", "A session was shut down")
)
// SessionKey represents an event label key that has a *Session value.
type SessionKey struct {
name string
description string
}
// NewSessionKey creates a new Key for *Session values.
func NewSessionKey(name, description string) *SessionKey {
return &SessionKey{name: name, description: description}
}
func (k *SessionKey) Name() string { return k.name }
func (k *SessionKey) Description() string { return k.description }
func (k *SessionKey) Format(w io.Writer, buf []byte, l label.Label) {
io.WriteString(w, k.From(l).ID())
}
// Of creates a new Label with this key and the supplied session.
func (k *SessionKey) Of(v *Session) label.Label { return label.OfValue(k, v) }
// Get can be used to get the session for the key from a label.Map.
func (k *SessionKey) Get(lm label.Map) *Session {
if t := lm.Find(k); t.Valid() {
return k.From(t)
}
return nil
}
// From can be used to get the session value from a Label.
func (k *SessionKey) From(t label.Label) *Session {
err, _ := t.UnpackValue().(*Session)
return err
}