Skip to content

Commit

Permalink
Introduce adapterSupportsMemoryEvent for cases where debug adapter do…
Browse files Browse the repository at this point in the history
…esn't send an memory event
  • Loading branch information
haydar-metin committed Mar 14, 2024
1 parent 1ad0202 commit ade769d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugin/memory-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class MemoryProvider {
protected readonly sessionDebugCapabilities = new Map<string, DebugProtocol.Capabilities | undefined>();
protected readonly sessionClientCapabilities = new Map<string, DebugProtocol.InitializeRequestArguments | undefined>();

/**
* Debug adapters can use the 'memory' event to indicate that the contents of a memory range has changed due to some request but do not specify which requests.
* We therefore track explicitly whether the debug adapter actually sends 'memory' events to know whether we should mimic the event ourselves.
*/
protected adapterSupportsMemoryEvent = false;

constructor(protected adapterRegistry: AdapterRegistry) {
}

Expand Down Expand Up @@ -70,6 +76,7 @@ export class MemoryProvider {
} else if (isDebugEvent('stopped', message)) {
this._onDidStopDebug.fire(session);
} else if (isDebugEvent('memory', message)) {
this.adapterSupportsMemoryEvent = true;
this._onDidWriteMemory.fire(message.body);
}
contributedTracker?.onDidSendMessage?.(message);
Expand Down Expand Up @@ -148,7 +155,7 @@ export class MemoryProvider {
public async writeMemory(args: DebugProtocol.WriteMemoryArguments): Promise<WriteMemoryResult> {
const session = this.assertCapability('supportsWriteMemoryRequest', 'write memory');
return sendRequest(session, 'writeMemory', args).then(response => {
if (!this.hasClientCapabilitiy(session, 'supportsMemoryEvent')) {
if (!this.adapterSupportsMemoryEvent || !this.hasClientCapabilitiy(session, 'supportsMemoryEvent')) {
// we only send out a custom event if we don't expect the client to handle the memory event
// since our client is VS Code we can assume that they will always support this but better to be safe
const offset = response?.offset ? (args.offset ?? 0) + response.offset : args.offset;
Expand Down

0 comments on commit ade769d

Please sign in to comment.