gitlab.com/Raven-IO/raven-delve@v1.22.4/service/dap/handles.go (about) 1 package dap 2 3 import "gitlab.com/Raven-IO/raven-delve/pkg/proc" 4 5 const startHandle = 1000 6 7 // handlesMap maps arbitrary values to unique sequential ids. 8 // This provides convenient abstraction of references, offering 9 // opacity and allowing simplification of complex identifiers. 10 // Based on 11 // https://github.com/microsoft/vscode-debugadapter-node/blob/master/adapter/src/handles.ts 12 type handlesMap struct { 13 nextHandle int 14 handleToVal map[int]interface{} 15 } 16 17 type fullyQualifiedVariable struct { 18 *proc.Variable 19 // A way to load this variable by either using all names in the hierarchic 20 // sequence above this variable (most readable when referenced by the UI) 21 // if available or a special expression based on: 22 // https://gitlab.com/Raven-IO/raven-delve/blob/master/Documentation/api/ClientHowto.md#loading-more-of-a-variable 23 // Empty if the variable cannot or should not be reloaded. 24 fullyQualifiedNameOrExpr string 25 // True if this represents variable scope 26 isScope bool 27 // startIndex is the index of the first child for an array or slice. 28 // This variable represents a chunk of the array, slice or map. 29 startIndex int 30 } 31 32 func newHandlesMap() *handlesMap { 33 return &handlesMap{startHandle, make(map[int]interface{})} 34 } 35 36 func (hs *handlesMap) reset() { 37 hs.nextHandle = startHandle 38 hs.handleToVal = make(map[int]interface{}) 39 } 40 41 func (hs *handlesMap) create(value interface{}) int { 42 next := hs.nextHandle 43 hs.nextHandle++ 44 hs.handleToVal[next] = value 45 return next 46 } 47 48 func (hs *handlesMap) get(handle int) (interface{}, bool) { 49 v, ok := hs.handleToVal[handle] 50 return v, ok 51 } 52 53 type variablesHandlesMap struct { 54 m *handlesMap 55 } 56 57 func newVariablesHandlesMap() *variablesHandlesMap { 58 return &variablesHandlesMap{newHandlesMap()} 59 } 60 61 func (hs *variablesHandlesMap) create(value *fullyQualifiedVariable) int { 62 return hs.m.create(value) 63 } 64 65 func (hs *variablesHandlesMap) get(handle int) (*fullyQualifiedVariable, bool) { 66 v, ok := hs.m.get(handle) 67 if !ok { 68 return nil, false 69 } 70 return v.(*fullyQualifiedVariable), true 71 } 72 73 func (hs *variablesHandlesMap) reset() { 74 hs.m.reset() 75 }