in src/vscodeIntegration/Treeview.ts [376:460]
private getElementInfo(childElement: Json.Property | Json.ObjectValue, elementInfo?: IElementInfo): IElementInfo {
let collapsible = false;
// Is childElement an Object (thus an array element, e.g. a top-level element of "resources")
if (childElement instanceof Json.ObjectValue) {
if (childElement.properties.length > 0) {
collapsible = true;
}
} else {
// Otherwise we're looking at a property (i.e., an object element)
// Is it a property with an Array value and does it have elements?
if (childElement.value instanceof Json.ArrayValue && childElement.value.elements.length > 0) {
// Is the first element in the Array an Object
if (childElement.value.elements[0].valueKind === Json.ValueKind.ObjectValue) {
collapsible = true;
}
} else if (childElement.value instanceof Json.ObjectValue && childElement.value.properties.length > 0) {
collapsible = true;
}
}
let result: IElementInfo = {
current: {
key: {
start: childElement.startIndex,
end: childElement.span.endIndex,
kind: undefined,
},
value: {
start: undefined,
end: undefined,
kind: undefined,
},
level: undefined,
collapsible: collapsible
},
parent: {
key: {
start: undefined,
end: undefined,
kind: undefined,
},
value: {
start: undefined,
end: undefined,
kind: undefined,
}
},
root: {
key: {
start: childElement.startIndex
}
}
};
if (childElement instanceof Json.Property) {
result.current.key.kind = childElement.valueKind;
// tslint:disable-next-line: strict-boolean-expressions
result.current.value.start = childElement.value ? childElement.value.startIndex : undefined;
result.current.value.end = childElement.value ? childElement.value.span.afterEndIndex : undefined;
result.current.value.kind = childElement.value ? childElement.value.valueKind : undefined;
} else {
result.current.key.kind = childElement.valueKind;
result.current.value.start = childElement.startIndex;
result.current.value.end = childElement.span.afterEndIndex;
result.current.value.kind = childElement.valueKind;
}
// Not a root element
if (elementInfo) {
result.parent.key.start = elementInfo.current.key.start;
result.parent.key.end = elementInfo.current.key.end;
result.parent.key.kind = elementInfo.current.key.kind;
result.parent.value.start = elementInfo.current.value.start;
result.parent.value.end = elementInfo.current.value.end;
result.root.key.start = elementInfo.root.key.start;
// tslint:disable-next-line: strict-boolean-expressions
result.current.level = (elementInfo.current.level || 0) + 1;
} else {
result.current.level = 1;
}
return result;
}