import { fileIdOrTreeKeyToRelativePath } from "./workspaceFileId";
var walkFileNodes = function walkFileNodes1(nodes, index) {
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    try {
        for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var node = _step.value;
            if ('children' in node) {
                walkFileNodes(node.children, index);
                continue;
            }
            var file = node;
            if (file.id) {
                var relativePath = fileIdOrTreeKeyToRelativePath(file.id);
                if (relativePath) {
                    index.set(relativePath, file);
                }
            }
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
};
/**
 * 按工作区相对路径索引平铺 {@link FileNode}
 * @description 供文件树叶子与 `Workspace.File` 的 `nodes` 对齐（如 `file:` 树 key 与 `workspace:` 列表 id）
 */ export var buildFileNodeRelativePathIndex = function buildFileNodeRelativePathIndex(nodes) {
    var index = new Map();
    walkFileNodes(nodes, index);
    return index;
};
