( dap: Dap.TestApi, variable: Dap.Variable, walker: (v: Dap.Variable, depth: number) => Promise<boolean> | boolean, depth = 0, )
| 16 | * first-search until walker returns false. |
| 17 | */ |
| 18 | export const walkVariables = async ( |
| 19 | dap: Dap.TestApi, |
| 20 | variable: Dap.Variable, |
| 21 | walker: (v: Dap.Variable, depth: number) => Promise<boolean> | boolean, |
| 22 | depth = 0, |
| 23 | ): Promise<void> => { |
| 24 | if (!(await walker(variable, depth))) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if (variable.variablesReference === undefined) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | const hasHints = |
| 33 | typeof variable.namedVariables === 'number' || typeof variable.indexedVariables === 'number'; |
| 34 | if (hasHints) { |
| 35 | if (variable.namedVariables) { |
| 36 | const named = await dap.variables({ |
| 37 | variablesReference: variable.variablesReference, |
| 38 | filter: 'named', |
| 39 | }); |
| 40 | for (const variable of named.variables) { |
| 41 | await walkVariables(dap, variable, walker, depth + 1); |
| 42 | } |
| 43 | } |
| 44 | if (variable.indexedVariables) { |
| 45 | const indexed = await dap.variables({ |
| 46 | variablesReference: variable.variablesReference, |
| 47 | filter: 'indexed', |
| 48 | start: 0, |
| 49 | count: variable.indexedVariables, |
| 50 | }); |
| 51 | for (const variable of indexed.variables) { |
| 52 | await walkVariables(dap, variable, walker, depth + 1); |
| 53 | } |
| 54 | } |
| 55 | } else { |
| 56 | const all = await dap.variables({ |
| 57 | variablesReference: variable.variablesReference, |
| 58 | }); |
| 59 | for (const variable of all.variables) { |
| 60 | await walkVariables(dap, variable, walker, depth + 1); |
| 61 | } |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | export class Logger { |
| 66 | private _dap: Dap.TestApi; |
no test coverage detected