Skip to content

Commit c560692

Browse files
authored
[trace-view] Added support for displaying type args (#22051)
## Description What the title says. Here is how types are displayed now: ![image](https://github.com/user-attachments/assets/943750ad-6c27-47aa-bde0-7ad3668a2e0e) ## Test plan A test has been updated to include type args and its output reflects the new display strategy
1 parent f85fa75 commit c560692

File tree

10 files changed

+3381
-3188
lines changed

10 files changed

+3381
-3188
lines changed

external-crates/move/crates/move-analyzer/trace-adapter/src/trace_utils.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface JSONStructTypeDescription {
3333
address: string;
3434
module: string;
3535
name: string;
36-
type_args: string[];
36+
type_args: JSONBaseType[];
3737
}
3838

3939
interface JSONStructType {
@@ -882,10 +882,38 @@ function processInstructionIfMacro(
882882
}
883883

884884

885-
885+
/**
886+
* Converts a JSON trace compound type to a string representation.
887+
* @param refPrefix prefix for the reference type.
888+
* @param address address of the package.
889+
* @param module name of the module.
890+
* @param name name of the type.
891+
* @param typeArgs type arguments of the compound type.
892+
* @returns string representation of the compound type.
893+
* */
894+
function JSONCompoundTypeToString(
895+
refPrefix: string,
896+
address: string,
897+
module: string,
898+
name: string,
899+
typeArgs: JSONBaseType[]
900+
): string {
901+
return refPrefix
902+
+ JSONTraceAddressToHexString(address)
903+
+ '::'
904+
+ module
905+
+ '::'
906+
+ name
907+
+ (typeArgs.length === 0
908+
? ''
909+
: '<' + typeArgs.map((t) => JSONTraceTypeToString(t)).join(',') + '>');
910+
}
886911

887912
/**
888913
* Converts a JSON trace type to a string representation.
914+
* @param baseType base type.
915+
* @param refType reference type.
916+
* @returns string representation of the type.
889917
*/
890918
function JSONTraceTypeToString(baseType: JSONBaseType, refType?: JSONTraceRefType): string {
891919
const refPrefix = refType === JSONTraceRefType.Mut
@@ -898,19 +926,17 @@ function JSONTraceTypeToString(baseType: JSONBaseType, refType?: JSONTraceRefTyp
898926
} else if ('vector' in baseType) {
899927
return refPrefix + `vector<${JSONTraceTypeToString(baseType.vector)}>`;
900928
} else if ('struct' in baseType) {
901-
return refPrefix
902-
+ JSONTraceAddressToHexString(baseType.struct.address)
903-
+ "::"
904-
+ baseType.struct.module
905-
+ "::"
906-
+ baseType.struct.name;
929+
return JSONCompoundTypeToString(refPrefix,
930+
baseType.struct.address,
931+
baseType.struct.module,
932+
baseType.struct.name,
933+
baseType.struct.type_args);
907934
} else {
908-
return refPrefix
909-
+ JSONTraceAddressToHexString(baseType.address)
910-
+ "::"
911-
+ baseType.module
912-
+ "::"
913-
+ baseType.name;
935+
return JSONCompoundTypeToString(refPrefix,
936+
baseType.address,
937+
baseType.module,
938+
baseType.name,
939+
baseType.type_args);
914940
}
915941
}
916942

external-crates/move/crates/move-analyzer/trace-adapter/tests/compound/build/compound/debug_info/m.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)