MCPcopy Index your code
hub / github.com/microsoft/vscode-js-debug / NodeVariable

Class NodeVariable

src/adapter/variableStore.ts:1022–1114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1020}
1021
1022class NodeVariable extends Variable {
1023 public override async toDap(
1024 previewContext: PreviewContextType,
1025 valueFormat?: Dap.ValueFormat,
1026 ): Promise<Dap.Variable> {
1027 const description = await this.description();
1028 const length = description?.node?.childNodeCount || 0;
1029 return {
1030 ...await super.toDap(previewContext, valueFormat),
1031 value: await this.getValuePreview(previewContext),
1032 variablesReference: this.id,
1033 indexedVariables: length > 100 ? length : undefined,
1034 namedVariables: length > 100 ? 1 : undefined,
1035 };
1036 }
1037
1038 public override async getChildren(params?: Dap.VariablesParamsExtended): Promise<Variable[]> {
1039 switch (params?.filter) {
1040 case 'indexed':
1041 return this.getNodeChildren(params.start, params.count);
1042 case 'named':
1043 return [this.getAttributesVar()];
1044 default:
1045 return [this.getAttributesVar(), ...(await this.getNodeChildren())];
1046 }
1047 }
1048
1049 private getAttributesVar() {
1050 return this.context.createVariable(
1051 NodeAttributes,
1052 {
1053 name: l10n.t('Node Attributes'),
1054 presentationHint: { visibility: 'internal' },
1055 sortOrder: Number.MAX_SAFE_INTEGER,
1056 },
1057 this.remoteObject,
1058 undefined,
1059 );
1060 }
1061
1062 private async getNodeChildren(start = -1, count = -1) {
1063 let slotsObject: Cdp.Runtime.RemoteObject;
1064 try {
1065 slotsObject = await getNodeChildren({
1066 cdp: this.context.cdp,
1067 generatePreview: false,
1068 args: [start, count],
1069 objectId: this.remoteObject.objectId,
1070 });
1071 } catch (e) {
1072 return [];
1073 }
1074
1075 const result = await this.context.createObjectPropertyVars(slotsObject);
1076 if (slotsObject.objectId) {
1077 await this.context.cdp.Runtime.releaseObject({ objectId: slotsObject.objectId });
1078 }
1079

Callers

nothing calls this directly

Calls 2

onceFunction · 0.90
describeNodeMethod · 0.80

Tested by

no test coverage detected