Skip to content

Commit

Permalink
Add Context for getVariables, StoreMemory, and ApplyMemory
Browse files Browse the repository at this point in the history
  • Loading branch information
WyoTwT committed Apr 10, 2024
1 parent 522b39b commit c472173
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/common/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const setOptionsType: RequestType<MemoryOptions, void> = { method: 'setOp
export const logMessageType: RequestType<string, void> = { method: 'logMessage' };
export const readMemoryType: RequestType<[ReadMemoryArguments, Context?], ReadMemoryResult> = { method: 'readMemory' };
export const writeMemoryType: RequestType<[WriteMemoryArguments, Context?], WriteMemoryResult> = { method: 'writeMemory' };
export const getVariablesType: RequestType<ReadMemoryArguments, VariableRange[]> = { method: 'getVariables' };
export const storeMemoryType: RequestType<StoreMemoryArguments, void> = { method: 'storeMemory' };
export const applyMemoryType: RequestType<ApplyMemoryArguments, ApplyMemoryResult> = { method: 'applyMemory' };
export const getVariablesType: RequestType<[ReadMemoryArguments, Context?], VariableRange[]> = { method: 'getVariables' };
export const storeMemoryType: RequestType<[StoreMemoryArguments, Context?], void> = { method: 'storeMemory' };
export const applyMemoryType: RequestType<[ApplyMemoryArguments, Context?], ApplyMemoryResult> = { method: 'applyMemory' };

export const showAdvancedOptionsType: NotificationType<void> = { method: 'showAdvancedOptions' };
export const getWebviewSelectionType: RequestType<void, WebviewSelection> = { method: 'getWebviewSelection' };
Expand Down
8 changes: 4 additions & 4 deletions src/plugin/adapter-registry/adapter-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { Logger } from '../logger';
/** Represents capabilities that may be achieved with particular debug adapters but are not part of the DAP */
export interface AdapterCapabilities {
/** Resolve variables known to the adapter to their locations. Fallback if {@link getResidents} is not present */
getVariables?(session: vscode.DebugSession): Promise<VariableRange[]>;
getVariables?(session: vscode.DebugSession, context?: Context): Promise<VariableRange[]>;
/** Resolve symbols resident in the memory at the specified range. Will be preferred to {@link getVariables} if present. */
getResidents?(session: vscode.DebugSession, params: DebugProtocol.ReadMemoryArguments): Promise<VariableRange[]>;
getResidents?(session: vscode.DebugSession, params: DebugProtocol.ReadMemoryArguments, context?: Context): Promise<VariableRange[]>;
/** Resolves the address of a given variable in bytes withthe current context. */
getAddressOfVariable?(session: vscode.DebugSession, variableName: string): Promise<string | undefined>;
getAddressOfVariable?(session: vscode.DebugSession, variableName: string, context?: Context): Promise<string | undefined>;
/** Resolves the size of a given variable in bytes within the current context. */
getSizeOfVariable?(session: vscode.DebugSession, variableName: string): Promise<bigint | undefined>;
getSizeOfVariable?(session: vscode.DebugSession, variableName: string, context?: Context): Promise<bigint | undefined>;
initializeAdapterTracker?(session: vscode.DebugSession): vscode.DebugAdapterTracker | undefined;
getContexts?(session: vscode.DebugSession): Promise<Context[]>;
readMemory?(session: vscode.DebugSession, params: ReadMemoryArguments, context?: Context): Promise<ReadMemoryResult>;
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/memory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ export class MemoryProvider {
});
}

public async getVariables(variableArguments: DebugProtocol.ReadMemoryArguments): Promise<VariableRange[]> {
public async getVariables([variableArguments, context]: ReadMemoryWithContext): Promise<VariableRange[]> {
const session = this.assertActiveSession('get variables');
const handler = this.adapterRegistry?.getHandlerForSession(session.type);
if (handler?.getResidents) { return handler.getResidents(session, variableArguments); }
return handler?.getVariables?.(session) ?? [];
if (handler?.getResidents) { return handler.getResidents(session, variableArguments, context); }
return handler?.getVariables?.(session, context) ?? [];
}

public async getAddressOfVariable(variableName: string): Promise<string | undefined> {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
}
}

protected async getVariables(request: ReadMemoryArguments): Promise<VariableRange[]> {
protected async getVariables(request: [ReadMemoryArguments, Context?]): Promise<VariableRange[]> {
try {
return await this.memoryProvider.getVariables(request);
} catch (err) {
Expand All @@ -316,7 +316,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
this.setMemoryViewSettings(ctx.messageParticipant, { visibleColumns });
}

protected async storeMemory(storeArguments: StoreMemoryArguments): Promise<void> {
protected async storeMemory(storeArguments: [StoreMemoryArguments, Context?]): Promise<void> {
// Even if we disable the command in VS Code through enablement or when condition, programmatic execution is still possible.
// However, we want to fail early in case the user tries to execute a disabled command
if (!this.memoryProvider.createContext().canRead) {
Expand Down
2 changes: 1 addition & 1 deletion src/webview/memory-webview-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class App extends React.Component<{}, MemoryAppState> {
}

protected storeMemory = async (): Promise<void> => {
await messenger.sendRequest(storeMemoryType, HOST_EXTENSION, { ...this.state.activeReadArguments });
await messenger.sendRequest(storeMemoryType, HOST_EXTENSION, [{ ...this.state.activeReadArguments }, this.state.context]);
};

protected applyMemory = async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/webview/variables/variable-decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class VariableDecorator implements ColumnContribution, Decorator {

async fetchData(currentViewParameters: ReadMemoryArguments): Promise<void> {
if (!this.active || !currentViewParameters.memoryReference || !currentViewParameters.count) { return; }
const visibleVariables = (await messenger.sendRequest(getVariablesType, HOST_EXTENSION, currentViewParameters))
const visibleVariables = (await messenger.sendRequest(getVariablesType, HOST_EXTENSION, [currentViewParameters, undefined]))
.map<BigIntVariableRange>(transmissible => {
const startAddress = BigInt(transmissible.startAddress);
return {
Expand Down

0 comments on commit c472173

Please sign in to comment.