@@ -18,22 +18,24 @@ import { DebugProtocol } from '@vscode/debugprotocol';
1818import * as vscode from 'vscode' ;
1919import { isDebugRequest , isDebugResponse } from '../../common/debug-requests' ;
2020import { VariableRange } from '../../common/memory-range' ;
21- import { ReadMemoryArguments , ReadMemoryResult , WriteMemoryArguments , WriteMemoryResult } from '../../common/messaging' ;
21+ import { Context , ReadMemoryArguments , ReadMemoryResult , WriteMemoryArguments , WriteMemoryResult } from '../../common/messaging' ;
2222import { Logger } from '../logger' ;
2323
2424/** Represents capabilities that may be achieved with particular debug adapters but are not part of the DAP */
2525export interface AdapterCapabilities {
2626 /** Resolve variables known to the adapter to their locations. Fallback if {@link getResidents} is not present */
27- getVariables ?( session : vscode . DebugSession ) : Promise < VariableRange [ ] > ;
27+ getVariables ?( session : vscode . DebugSession , context ?: Context ) : Promise < VariableRange [ ] > ;
2828 /** Resolve symbols resident in the memory at the specified range. Will be preferred to {@link getVariables} if present. */
29- getResidents ?( session : vscode . DebugSession , params : DebugProtocol . ReadMemoryArguments ) : Promise < VariableRange [ ] > ;
29+ getResidents ?( session : vscode . DebugSession , params : DebugProtocol . ReadMemoryArguments , context ?: Context ) : Promise < VariableRange [ ] > ;
3030 /** Resolves the address of a given variable in bytes with the current context. */
31- getAddressOfVariable ?( session : vscode . DebugSession , variableName : string ) : Promise < string | undefined > ;
31+ getAddressOfVariable ?( session : vscode . DebugSession , variableName : string , context ?: Context ) : Promise < string | undefined > ;
3232 /** Resolves the size of a given variable in bytes within the current context. */
33- getSizeOfVariable ?( session : vscode . DebugSession , variableName : string ) : Promise < bigint | undefined > ;
33+ getSizeOfVariable ?( session : vscode . DebugSession , variableName : string , context ?: Context ) : Promise < bigint | undefined > ;
3434 initializeAdapterTracker ?( session : vscode . DebugSession ) : vscode . DebugAdapterTracker | undefined ;
35- readMemory ?( session : vscode . DebugSession , params : ReadMemoryArguments ) : Promise < ReadMemoryResult > ;
36- writeMemory ?( session : vscode . DebugSession , params : WriteMemoryArguments ) : Promise < WriteMemoryResult > ;
35+ readMemory ?( session : vscode . DebugSession , params : ReadMemoryArguments , context ?: Context ) : Promise < ReadMemoryResult > ;
36+ writeMemory ?( session : vscode . DebugSession , params : WriteMemoryArguments , context ?: Context ) : Promise < WriteMemoryResult > ;
37+ getContexts ?( session : vscode . DebugSession ) : Promise < Context [ ] > ;
38+ getCurrentContext ?( session : vscode . DebugSession ) : Promise < Context | undefined > ;
3739}
3840
3941export type WithChildren < Original > = Original & { children ?: Array < WithChildren < DebugProtocol . Variable > > } ;
@@ -104,14 +106,14 @@ export class AdapterVariableTracker implements vscode.DebugAdapterTracker {
104106 this . pendingMessages . clear ( ) ;
105107 }
106108
107- async getLocals ( session : vscode . DebugSession ) : Promise < VariableRange [ ] > {
109+ async getLocals ( session : vscode . DebugSession , context ?: Context ) : Promise < VariableRange [ ] > {
108110 this . logger . debug ( 'Retrieving local variables in' , session . name + ' Current variables:\n' , this . variablesTree ) ;
109111 if ( this . currentFrame === undefined ) { return [ ] ; }
110112 const maybeRanges = await Promise . all ( Object . values ( this . variablesTree ) . reduce < Array < Promise < VariableRange | undefined > > > ( ( previous , parent ) => {
111113 if ( this . isDesiredVariable ( parent ) && parent . children ?. length ) {
112114 this . logger . debug ( 'Resolving children of' , parent . name ) ;
113115 parent . children . forEach ( child => {
114- previous . push ( this . variableToVariableRange ( child , session ) ) ;
116+ previous . push ( this . variableToVariableRange ( child , session , context ) ) ;
115117 } ) ;
116118 } else {
117119 this . logger . debug ( 'Ignoring' , parent . name ) ;
@@ -125,19 +127,22 @@ export class AdapterVariableTracker implements vscode.DebugAdapterTracker {
125127 return candidate . presentationHint !== 'registers' && candidate . name !== 'Registers' ;
126128 }
127129
128- protected variableToVariableRange ( _variable : DebugProtocol . Variable , _session : vscode . DebugSession ) : Promise < VariableRange | undefined > {
130+ protected variableToVariableRange ( _variable : DebugProtocol . Variable , _session : vscode . DebugSession , _context ?: Context ) : Promise < VariableRange | undefined > {
129131 throw new Error ( 'To be implemented by derived classes!' ) ;
130132 }
131133
132134 /** Resolves the address of a given variable in bytes within the current context. */
133- getAddressOfVariable ?( variableName : string , session : vscode . DebugSession ) : Promise < string | undefined > ;
135+ getAddressOfVariable ?( variableName : string , session : vscode . DebugSession , context ?: Context ) : Promise < string | undefined > ;
134136
135137 /** Resolves the size of a given variable in bytes within the current context. */
136- getSizeOfVariable ?( variableName : string , session : vscode . DebugSession ) : Promise < bigint | undefined > ;
138+ getSizeOfVariable ?( variableName : string , session : vscode . DebugSession , context ?: Context ) : Promise < bigint | undefined > ;
137139
138- readMemory ?( session : vscode . DebugSession , params : ReadMemoryArguments ) : Promise < ReadMemoryResult > ;
140+ readMemory ?( session : vscode . DebugSession , params : ReadMemoryArguments , context : Context ) : Promise < ReadMemoryResult > ;
139141
140- writeMemory ?( session : vscode . DebugSession , params : WriteMemoryArguments ) : Promise < WriteMemoryResult > ;
142+ writeMemory ?( session : vscode . DebugSession , params : WriteMemoryArguments , context : Context ) : Promise < WriteMemoryResult > ;
143+
144+ getContexts ?( session : vscode . DebugSession ) : Promise < Context [ ] > ;
145+ getCurrentContext ?( session : vscode . DebugSession ) : Promise < Context | undefined > ;
141146}
142147
143148export class VariableTracker implements AdapterCapabilities {
@@ -159,15 +164,15 @@ export class VariableTracker implements AdapterCapabilities {
159164 }
160165 }
161166
162- async getVariables ( session : vscode . DebugSession ) : Promise < VariableRange [ ] > {
163- return this . sessions . get ( session . id ) ?. getLocals ( session ) ?? [ ] ;
167+ async getVariables ( session : vscode . DebugSession , context ?: Context ) : Promise < VariableRange [ ] > {
168+ return this . sessions . get ( session . id ) ?. getLocals ( session , context ) ?? [ ] ;
164169 }
165170
166- async getAddressOfVariable ( session : vscode . DebugSession , variableName : string ) : Promise < string | undefined > {
167- return this . sessions . get ( session . id ) ?. getAddressOfVariable ?.( variableName , session ) ;
171+ async getAddressOfVariable ( session : vscode . DebugSession , variableName : string , context ?: Context ) : Promise < string | undefined > {
172+ return this . sessions . get ( session . id ) ?. getAddressOfVariable ?.( variableName , session , context ) ;
168173 }
169174
170- async getSizeOfVariable ( session : vscode . DebugSession , variableName : string ) : Promise < bigint | undefined > {
171- return this . sessions . get ( session . id ) ?. getSizeOfVariable ?.( variableName , session ) ;
175+ async getSizeOfVariable ( session : vscode . DebugSession , variableName : string , context ?: Context ) : Promise < bigint | undefined > {
176+ return this . sessions . get ( session . id ) ?. getSizeOfVariable ?.( variableName , session , context ) ;
172177 }
173178}
0 commit comments