private getIconPath()

in src/vscodeIntegration/Treeview.ts [470:520]


    private getIconPath(elementInfo: IElementInfo): string | undefined {

        let icon: string | undefined;
        const keyOrResourceNode = this.tree?.getValueAtCharacterIndex(elementInfo.current.key.start, ContainsBehavior.strict);

        // Is current element a root element?
        if (elementInfo.current.level === 1) {
            if (keyOrResourceNode) {
                icon = this.getIcon(topLevelIcons, keyOrResourceNode.toString(), "");
            }
        } else if (elementInfo.current.level === 2) {
            // Is current element an element of a root element?

            // Get root value
            const rootNode = this.tree?.getValueAtCharacterIndex(elementInfo.root.key.start, ContainsBehavior.strict);
            if (rootNode) {
                icon = this.getIcon(topLevelChildIconsByRootNode, rootNode.toString(), "");
            }
        }

        // If resourceType element is found on resource objects set to specific resourceType Icon or else a default resource icon
        // tslint:disable-next-line: strict-boolean-expressions
        if (elementInfo.current.level && elementInfo.current.level > 1) {
            const rootNode = this.tree?.getValueAtCharacterIndex(elementInfo.root.key.start, ContainsBehavior.strict);

            if (elementInfo.current.key.kind === Json.ValueKind.ObjectValue &&
                rootNode && rootNode.toString().toUpperCase() === "resources".toUpperCase() && keyOrResourceNode instanceof Json.ObjectValue) {
                // tslint:disable-next-line:one-variable-per-declaration
                for (var i = 0, il = keyOrResourceNode.properties.length; i < il; i++) {
                    const name = keyOrResourceNode.properties[i].nameValue;
                    if (name.toString().toUpperCase() === "type".toUpperCase()) {
                        const value = keyOrResourceNode.properties[i].value;
                        if (value) {
                            let resourceType = value.toString().toUpperCase();
                            icon = this.getIcon(resourceIcons, resourceType, "resources.svg");
                        }
                    }
                }
            }

            if (rootNode && rootNode.toString().toUpperCase() === "functions".toUpperCase()) {
                icon = this.getFunctionsIcon(elementInfo, keyOrResourceNode);
            }
        }

        if (icon) {
            return path.join(iconsPath, icon);
        }

        return undefined;
    }