MCPcopy
hub / github.com/microsoft/vscode-js-debug / SetOrMapVariable

Class SetOrMapVariable

src/adapter/variableStore.ts:1138–1171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1136const entriesVariableName = '[[Entries]]';
1137
1138class SetOrMapVariable extends ObjectVariable {
1139 private readonly size?: number;
1140 public readonly isMap: boolean;
1141 private readonly baseChildren = once(() => super.getChildren({ variablesReference: this.id }));
1142
1143 constructor(context: VariableContext, remoteObject: Cdp.Runtime.RemoteObject) {
1144 super(context, remoteObject, NoCustomStringRepr);
1145 this.isMap = remoteObject.subtype === 'map';
1146 const cast = remoteObject.preview as MapPreview | SetPreview | undefined;
1147 this.size = Number(cast?.properties.find(p => p.name === 'size')?.value) ?? undefined;
1148 }
1149
1150 public override async toDap(previewContext: PreviewContextType): Promise<Dap.Variable> {
1151 const dap = await super.toDap(previewContext);
1152 if (this.size && this.size > 100) {
1153 dap.indexedVariables = this.size;
1154 }
1155
1156 return dap;
1157 }
1158
1159 public override async getChildren(params: Dap.VariablesParams): Promise<Variable[]> {
1160 const baseChildren = await this.baseChildren();
1161 const entryChildren = await baseChildren
1162 .find(c => c.name === entriesVariableName)
1163 ?.getChildren(params);
1164
1165 return [
1166 // filter to only show the actualy entries, not the array prototype/length
1167 ...(entryChildren || []).filter(v => v.sortOrder === SortOrder.Default),
1168 ...baseChildren.filter(c => c.name !== entriesVariableName),
1169 ];
1170 }
1171}
1172
1173class ArrayVariable extends ObjectVariable {
1174 private length = 0;

Callers

nothing calls this directly

Calls 2

onceFunction · 0.90
getChildrenMethod · 0.65

Tested by

no test coverage detected