Skip to content

Commit

Permalink
Fixed displaying reference types
Browse files Browse the repository at this point in the history
  • Loading branch information
awelc committed Oct 15, 2024
1 parent 2b7befe commit e10fdd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
CompoundType,
IRuntimeRefValue
} from './runtime';
import { run } from 'node:test';

const enum LogLevel {
Log = 'log',
Expand Down Expand Up @@ -278,10 +277,16 @@ export class MoveDebugSession extends LoggingDebugSession {
* Converts a runtime reference value to a DAP variable.
*
* @param value reference value.
* @param name name of variable containing the reference value.
* @param type optional type of the variable containing the reference value.
* @returns a DAP variable.
* @throws Error with a descriptive error message if conversion fails.
*/
private convertRefValue(value: IRuntimeRefValue): DebugProtocol.Variable {
private convertRefValue(
value: IRuntimeRefValue,
name: string,
type?: string
): DebugProtocol.Variable {
const frameID = value.loc.frameID;
const localIndex = value.loc.localIndex;
const runtimeStack = this.runtime.stack();
Expand All @@ -307,7 +312,7 @@ export class MoveDebugSession extends LoggingDebugSession {
+ frameID);
}

return this.convertRuntimeValue(local.value, local.name, local.type);
return this.convertRuntimeValue(local.value, name, type);
}

/**
Expand Down Expand Up @@ -340,21 +345,26 @@ export class MoveDebugSession extends LoggingDebugSession {
};
} else if ('fields' in value) {
const compoundValueReference = this.variableHandles.create(value);
const accessChainParts = value.type.split('::');
// use type if available as it will have information about whether
// it's a reference or not (e.g., `&mut 0x42::mod::SomeStruct`),
// as opposed to the type that come with the value
// (e.g., `0x42::mod::SomeStruct`)
const actualType = type ? type : value.type;
const accessChainParts = actualType.split('::');
const datatypeName = accessChainParts[accessChainParts.length - 1];
return {
name,
type: value.variantName
? value.type + '::' + value.variantName
: value.type,
? actualType + '::' + value.variantName
: actualType,
value: (value.variantName
? datatypeName + '::' + value.variantName
: datatypeName
) + '{...}',
variablesReference: compoundValueReference
};
} else {
return this.convertRefValue(value);
return this.convertRefValue(value, name, type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ function JSONTraceTypeToString(baseType: JSONBaseType, refType?: JSONTraceRefTyp
? '&'
: '');
if (typeof baseType === 'string') {
return baseType;
return refPrefix + baseType;
} else if ('vector' in baseType) {
return refPrefix + `vector<${JSONTraceTypeToString(baseType.vector)}>`;
} else {
Expand Down

0 comments on commit e10fdd1

Please sign in to comment.