"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtHostTreeViews = void 0;
const tslib_1 = require("tslib");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const vscode_1 = require("../../../common/vscode");
const converter_1 = require("../../../common/vscode/converter");
const types = tslib_1.__importStar(require("../../../common/vscode/ext-types"));
class ExtHostTreeViews {
    constructor(rpc, extHostCommand) {
        this.extHostCommand = extHostCommand;
        this.treeViews = new Map();
        this.treeDragAndDropService = new vscode_1.TreeviewsService();
        this.proxy = rpc.getProxy(vscode_1.MainThreadAPIIdentifier.MainThreadTreeView);
        extHostCommand.registerArgumentProcessor({
            processArgument: (arg) => {
                if (!vscode_1.TreeViewSelection.is(arg)) {
                    return arg;
                }
                const { treeViewId, treeItemId } = arg;
                const treeView = this.treeViews.get(treeViewId);
                return treeView && treeView.getTreeItem(treeItemId);
            },
        });
    }
    registerTreeDataProvider(treeViewId, treeDataProvider) {
        const treeView = this.createTreeView(treeViewId, { treeDataProvider });
        return ide_core_common_1.Disposable.create(() => {
            this.treeViews.delete(treeViewId);
            treeView.dispose();
        });
    }
    createTreeView(treeViewId, options) {
        if (!options || !options.treeDataProvider) {
            throw new Error('Options with treeDataProvider is mandatory');
        }
        const treeView = new ExtHostTreeView(treeViewId, options, this.proxy, this.extHostCommand);
        this.treeViews.set(treeViewId, treeView);
        return {
            get onDidExpandElement() {
                return treeView.onDidExpandElement;
            },
            get onDidCollapseElement() {
                return treeView.onDidCollapseElement;
            },
            get selection() {
                return treeView.selectedElements;
            },
            get onDidChangeSelection() {
                return treeView.onDidChangeSelection;
            },
            get visible() {
                return treeView.visible;
            },
            get onDidChangeVisibility() {
                return treeView.onDidChangeVisibility;
            },
            get onDidChangeCheckboxState() {
                return treeView.onDidChangeCheckboxState;
            },
            get message() {
                return treeView.message;
            },
            set message(message) {
                treeView.message = message;
            },
            get title() {
                return treeView.title;
            },
            set title(title) {
                treeView.title = title;
            },
            get description() {
                return treeView.description;
            },
            set description(description) {
                treeView.description = description;
            },
            get badge() {
                return treeView.badge;
            },
            set badge(badge) {
                treeView.badge = badge;
            },
            reveal: (element, options) => treeView.reveal(element, options),
            dispose: () => {
                this.treeViews.delete(treeViewId);
                treeView.dispose();
            },
        };
    }
    /**
     * 获取子节点
     * @param treeViewId
     * @param treeItemId 可选参数，如果不传则获取根节点
     */
    async $getChildren(treeViewId, treeItemId) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        return treeView.getChildren(treeItemId);
    }
    /**
     * 获取子节点
     * @param treeViewId
     * @param treeItemId
     */
    async $resolveTreeItem(treeViewId, treeItemId, token) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        return treeView.resolveTreeItem(treeItemId, token);
    }
    /**
     * 设置节点展开属性
     * @param treeViewId
     * @param treeItemId
     * @param expanded
     */
    async $setExpanded(treeViewId, treeItemId, expanded) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        if (expanded) {
            return treeView.onExpanded(treeItemId);
        }
        else {
            return treeView.onCollapsed(treeItemId);
        }
    }
    /**
     * 设置选中的节点
     * @param treeViewId
     * @param treeItemIds
     */
    async $setSelection(treeViewId, treeItemIds) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        treeView.setSelection(treeItemIds);
    }
    /**
     * 设置节点是否可见
     * @param treeViewId
     * @param isVisible
     */
    async $setVisible(treeViewId, isVisible) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        treeView.setVisible(isVisible);
    }
    /**
     * 设置节点的选择状态
     * @param treeViewId
     * @param items
     * @returns
     */
    $checkStateChanged(treeViewId, items) {
        const treeView = this.treeViews.get(treeViewId);
        if (!treeView) {
            throw new Error('No tree view with id ' + treeViewId);
        }
        return treeView.checkStateChanged(items);
    }
    async $handleDrop(destinationViewId, requestId, treeDataTransferDTO, targetItemHandle, token, operationUuid, sourceViewId, sourceTreeItemHandles) {
        const treeView = this.treeViews.get(destinationViewId);
        if (!treeView) {
            return Promise.reject(new Error(`No tree view with id '${destinationViewId}' registered.`));
        }
        const treeDataTransfer = converter_1.DataTransfer.toDataTransfer(treeDataTransferDTO, async (dataItemIndex) => (await this.proxy.$resolveDropFileData(destinationViewId, requestId, dataItemIndex)).buffer);
        if (sourceViewId === destinationViewId && sourceTreeItemHandles) {
            await this.addAdditionalTransferItems(treeDataTransfer, treeView, sourceTreeItemHandles, token, operationUuid);
        }
        return treeView.onDrop(treeDataTransfer, targetItemHandle, token);
    }
    async addAdditionalTransferItems(treeDataTransfer, treeView, sourceTreeItemHandles, token, operationUuid) {
        var _a;
        const existingTransferOperation = this.treeDragAndDropService.removeDragOperationTransfer(operationUuid);
        if (existingTransferOperation) {
            (_a = (await existingTransferOperation)) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
                if (value) {
                    treeDataTransfer.set(key, value);
                }
            });
        }
        else if (operationUuid && treeView.handleDrag) {
            const willDropPromise = treeView.handleDrag(sourceTreeItemHandles, treeDataTransfer, token);
            this.treeDragAndDropService.addDragOperationTransfer(operationUuid, willDropPromise);
            await willDropPromise;
        }
        return treeDataTransfer;
    }
    async $handleDrag(sourceViewId, sourceTreeItemHandles, operationUuid, token) {
        const treeView = this.treeViews.get(sourceViewId);
        if (!treeView) {
            return Promise.reject(new Error(`No tree view with id '${sourceViewId}' registered.`));
        }
        const treeDataTransfer = await this.addAdditionalTransferItems(new types.DataTransfer(), treeView, sourceTreeItemHandles, token, operationUuid);
        if (!treeDataTransfer) {
            return;
        }
        return converter_1.DataTransfer.toDataTransferDTO(treeDataTransfer);
    }
}
exports.ExtHostTreeViews = ExtHostTreeViews;
class ExtHostTreeView {
    constructor(treeViewId, options, proxy, commands) {
        var _a, _b, _c, _d, _e, _f;
        this.treeViewId = treeViewId;
        this.options = options;
        this.proxy = proxy;
        this.commands = commands;
        this.onDidExpandElementEmitter = new ide_core_common_1.Emitter();
        this.onDidExpandElement = this.onDidExpandElementEmitter.event;
        this.onDidCollapseElementEmitter = new ide_core_common_1.Emitter();
        this.onDidCollapseElement = this.onDidCollapseElementEmitter.event;
        this.onDidChangeSelectionEmitter = new ide_core_common_1.Emitter();
        this.onDidChangeSelection = this.onDidChangeSelectionEmitter.event;
        this.onDidChangeVisibilityEmitter = new ide_core_common_1.Emitter();
        this.onDidChangeVisibility = this.onDidChangeVisibilityEmitter.event;
        this.onDidChangeCheckboxStateEmitter = new ide_core_common_1.Emitter();
        this.onDidChangeCheckboxState = this.onDidChangeCheckboxStateEmitter.event;
        this._visible = false;
        this.selectedItemIds = new Set();
        this.id2Element = new Map();
        this.element2TreeViewItem = new Map();
        this.element2VSCodeTreeItem = new Map();
        this.disposable = new ide_core_common_1.DisposableStore();
        this._onDidChangeData = new ide_core_common_1.Emitter();
        this._badge = undefined;
        this.roots = undefined;
        this.nodes = new Map();
        this.refreshPromise = Promise.resolve();
        this.refreshQueue = Promise.resolve();
        this._refreshCancellationSource = new ide_core_common_1.CancellationTokenSource();
        this.dataProvider = this.options.treeDataProvider;
        this.dndController = this.options.dragAndDropController;
        const dropMimeTypes = (_b = (_a = this.dndController) === null || _a === void 0 ? void 0 : _a.dropMimeTypes) !== null && _b !== void 0 ? _b : [];
        const dragMimeTypes = (_d = (_c = this.dndController) === null || _c === void 0 ? void 0 : _c.dragMimeTypes) !== null && _d !== void 0 ? _d : [];
        const hasHandleDrag = !!((_e = this.dndController) === null || _e === void 0 ? void 0 : _e.handleDrag);
        const hasHandleDrop = !!((_f = this.dndController) === null || _f === void 0 ? void 0 : _f.handleDrop);
        this.disposable.add(this._onDidChangeData);
        // 将 options 直接取值，避免循环引用导致序列化异常
        proxy.$registerTreeDataProvider(treeViewId, {
            manageCheckboxStateManually: options.manageCheckboxStateManually,
            showCollapseAll: !!options.showCollapseAll,
            canSelectMany: !!options.canSelectMany,
            dropMimeTypes,
            dragMimeTypes,
            hasHandleDrag,
            hasHandleDrop,
        });
        if (this.dataProvider.onDidChangeTreeData) {
            const dispose = this.dataProvider.onDidChangeTreeData((itemToRefresh) => {
                this._onDidChangeData.fire({ element: itemToRefresh, message: false });
            });
            if (dispose) {
                this.disposable.add(dispose);
            }
        }
        this.disposable.add((0, ide_core_common_1.toDisposable)(() => this.id2Element.clear()));
        this.disposable.add((0, ide_core_common_1.toDisposable)(() => this.element2TreeViewItem.clear()));
        this.disposable.add((0, ide_core_common_1.toDisposable)(() => this.element2VSCodeTreeItem.clear()));
        this.disposable.add((0, ide_core_common_1.toDisposable)(() => this.nodes.clear()));
        this.disposable.add((0, ide_core_common_1.toDisposable)(() => proxy.$unregisterTreeDataProvider(treeViewId)));
        let refreshingPromise;
        let promiseCallback;
        this.disposable.add(ide_core_common_1.Event.debounce(this.onDidChangeData, (result, current) => {
            if (!result) {
                result = { message: false, elements: [] };
            }
            if (current.element !== false) {
                if (!refreshingPromise) {
                    refreshingPromise = new Promise((c) => (promiseCallback = c));
                    this.refreshPromise = this.refreshPromise.then(() => refreshingPromise);
                }
                if (Array.isArray(current.element)) {
                    result.elements.push(...current.element);
                }
                else {
                    result.elements.push(current.element);
                }
            }
            if (current.message) {
                result.message = true;
            }
            return result;
        }, 200, true)(({ message, elements }) => {
            if (elements.length) {
                this.refreshQueue = this.refreshQueue.then(() => {
                    const _promiseCallback = promiseCallback;
                    refreshingPromise = null;
                    return this.refresh(elements).then(() => _promiseCallback());
                });
            }
            if (message) {
                this.proxy.$setMessage(this.treeViewId, this._message);
            }
        }));
    }
    refresh(elements) {
        const hasRoot = elements.some((element) => !element);
        // 当存在根节点时，整颗树刷新，无需考虑子节点情况
        if (hasRoot) {
            // 取消正在进行的刷新操作
            this._refreshCancellationSource.cancel();
            this._refreshCancellationSource = new ide_core_common_1.CancellationTokenSource();
            this.clearCache();
            return this.proxy.$refresh(this.treeViewId);
        }
        else {
            // TODO: 这里可以根据路径关系进一步合并多余的刷新操作，目前实现必要性不大
            const handlesToRefresh = this.getTreesNodeToRefresh(elements);
            if (handlesToRefresh.length) {
                return this.refreshTreeNodes(handlesToRefresh);
            }
        }
        return Promise.resolve(undefined);
    }
    clearCache() {
        this.roots = undefined;
        this.nodes.clear();
        this.id2Element.clear();
        this.element2TreeViewItem.clear();
        this.element2VSCodeTreeItem.clear();
    }
    getTreesNodeToRefresh(elements) {
        const treeNodeToUpdate = new Set();
        const nodes = elements.map((element) => {
            const treeViewItem = this.element2TreeViewItem.get(element);
            if (treeViewItem) {
                return treeViewItem;
            }
        });
        for (const node of nodes) {
            if (node) {
                treeNodeToUpdate.add(node);
            }
        }
        return Array.from(treeNodeToUpdate);
    }
    async refreshTreeNodes(itemHandles) {
        await Promise.all(itemHandles.map((itemsToRefresh) => this.proxy.$refresh(this.treeViewId, itemsToRefresh)));
    }
    dispose() {
        this._refreshCancellationSource.dispose();
        this.disposable.dispose();
    }
    get onDidChangeData() {
        return this._onDidChangeData.event;
    }
    get title() {
        return this._title;
    }
    set title(value) {
        this.proxy.$setTitle(this.treeViewId, value);
        this._title = value;
    }
    get description() {
        return this._description;
    }
    set description(value) {
        this.proxy.$setDescription(this.treeViewId, value);
        this._description = value;
    }
    get message() {
        return this._message;
    }
    set message(value) {
        this._message = value;
        this._onDidChangeData.fire({ message: true, element: false });
    }
    get visible() {
        return this._visible;
    }
    get badge() {
        return this._badge;
    }
    set badge(badge) {
        this._badge = badge;
        this.proxy.$setBadge(this.treeViewId, badge);
    }
    get selectedElements() {
        const items = [];
        for (const id of this.selectedItemIds) {
            const item = this.getTreeItem(id);
            if (item) {
                items.push(item);
            }
        }
        return items;
    }
    async reveal(element, options) {
        // 在缓存中查找对应节点
        let elementId = element.id;
        if (!elementId) {
            const treeViewItem = this.element2TreeViewItem.get(element);
            if (treeViewItem) {
                elementId = treeViewItem.id;
            }
        }
        if (typeof this.dataProvider.getParent !== 'function') {
            throw new Error("Required registered TreeDataProvider to implement 'getParent' method to access 'reveal' method");
        }
        await this.refreshPromise;
        if (elementId) {
            const revealOptions = {
                expand: options === null || options === void 0 ? void 0 : options.expand,
                focus: options === null || options === void 0 ? void 0 : options.focus,
                select: options === null || options === void 0 ? void 0 : options.select,
            };
            await this.proxy.$reveal(this.treeViewId, elementId, revealOptions);
        }
        else {
            // need reveal the root
            await this.proxy.$reveal(this.treeViewId, undefined, options);
        }
    }
    getViewTreeId(value, treeItem) {
        let id = value.id || treeItem.id;
        if (!id) {
            // 获取Label属性
            let label;
            const treeItemLabel = treeItem.label;
            if (treeItemLabel) {
                label = treeItemLabel;
            }
            // 当没有指定label时尝试使用resourceUri
            if (!label && treeItem.resourceUri) {
                label = treeItem.resourceUri.path.toString();
                label = decodeURIComponent(label);
                if (label.indexOf('/') >= 0) {
                    label = label.substring(label.lastIndexOf('/') + 1);
                }
            }
            const _label = (0, ide_core_common_1.isString)(label) ? label : label === null || label === void 0 ? void 0 : label.label;
            id = [this.treeViewId, _label, (0, ide_core_common_1.randomString)(4)].filter(Boolean).join(':');
        }
        return id;
    }
    async resolveParentChain(element) {
        const parentChain = [];
        // will receive `null` or `undefined` if `element` is a child of root.
        let parent = await this.dataProvider.getParent(element);
        while (parent) {
            parentChain.push(parent);
            parent = await this.dataProvider.getParent(parent);
        }
        return parentChain;
    }
    getTreeItem(treeItemId) {
        if (treeItemId) {
            return this.id2Element.get(treeItemId);
        }
    }
    async handleDrag(sourceTreeItemHandles, treeDataTransfer, token) {
        var _a;
        const extensionTreeItems = [];
        for (const sourceHandle of sourceTreeItemHandles) {
            const extensionItem = this.getTreeItem(sourceHandle);
            if (extensionItem) {
                extensionTreeItems.push(extensionItem);
            }
        }
        if (!((_a = this.dndController) === null || _a === void 0 ? void 0 : _a.handleDrag) || extensionTreeItems.length === 0) {
            return;
        }
        await this.dndController.handleDrag(extensionTreeItems, treeDataTransfer, token);
        return treeDataTransfer;
    }
    get hasHandleDrag() {
        var _a;
        return !!((_a = this.dndController) === null || _a === void 0 ? void 0 : _a.handleDrag);
    }
    async onDrop(treeDataTransfer, targetHandleOrNode, token) {
        var _a;
        const target = targetHandleOrNode ? this.getTreeItem(targetHandleOrNode) : undefined;
        if ((!target && targetHandleOrNode) || !((_a = this.dndController) === null || _a === void 0 ? void 0 : _a.handleDrop)) {
            return;
        }
        return (0, ide_core_common_1.asPromise)(() => { var _a; return ((_a = this.dndController) === null || _a === void 0 ? void 0 : _a.handleDrop) ? this.dndController.handleDrop(target, treeDataTransfer, token) : undefined; });
    }
    async checkStateChanged(items) {
        const transformed = [];
        items.forEach((item) => {
            const node = this.getTreeItem(item.treeItemId);
            if (node) {
                transformed.push([node, item.checked ? vscode_1.TreeItemCheckboxState.Checked : vscode_1.TreeItemCheckboxState.Unchecked]);
                const treeViewItem = this.element2TreeViewItem.get(node);
                if (treeViewItem && treeViewItem.checkboxInfo) {
                    treeViewItem.checkboxInfo.checked = item.checked;
                }
            }
        });
        this.onDidChangeCheckboxStateEmitter.fire({
            items: transformed,
        });
    }
    /**
     * 在节点被点击或者打开时，获取原有的 command 为 undefined 时被调用
     * 在节点被 Hover 时，获取原有的 tooltip 为 undefined 时被调用
     */
    async resolveTreeItem(treeItemId, token) {
        var _a;
        if (!this.dataProvider.resolveTreeItem) {
            return;
        }
        if (token.isCancellationRequested) {
            return;
        }
        const cache = this.getTreeItem(treeItemId);
        if (cache) {
            const node = this.element2VSCodeTreeItem.get(cache);
            if (!node) {
                return undefined;
            }
            const resolve = (_a = (await this.dataProvider.resolveTreeItem(node, cache, token))) !== null && _a !== void 0 ? _a : node;
            node.tooltip = resolve.tooltip;
            node.command = resolve.command;
            return this.toTreeViewItem(node);
        }
        return;
    }
    /**
     * Get the children of `element` or root if no element is passed.
     *
     * @param element The element from which the provider gets children. Can be `undefined`.
     * @return Children of `element` or root if no element is passed.
     */
    async resolveChildren(element) {
        const treeItems = [];
        const results = await this.dataProvider.getChildren(element);
        if (!results) {
            return;
        }
        for (const value of results.values()) {
            // 遍历treeDataProvider获取的值生成节点
            if (this._refreshCancellationSource.token.isCancellationRequested) {
                return;
            }
            const treeViewItem = await this.cacheElement(value);
            treeItems.push(treeViewItem);
        }
        return treeItems;
    }
    async cacheElement(value) {
        const treeItem = await this.dataProvider.getTreeItem(value);
        const id = this.getViewTreeId(value, treeItem);
        this.id2Element.set(id, value);
        const treeViewItem = this.toTreeViewItem(treeItem, {
            id,
        });
        this.element2TreeViewItem.set(value, treeViewItem);
        this.element2VSCodeTreeItem.set(value, treeItem);
        return treeViewItem;
    }
    /**
     * @param treeItemId 可选参数，如果不传则获取根节点
     */
    async getChildren(treeItemId) {
        // 缓存中获取节点
        const cachedElement = this.getTreeItem(treeItemId);
        // 没有 cachedElement 时，获取根节点，如果根节点已经初始化则直接返回
        if (!cachedElement && this.roots) {
            return this.roots;
        }
        let children;
        if (this._refreshCancellationSource.token.isCancellationRequested) {
            children = undefined;
        }
        else {
            const results = await this.resolveChildren(cachedElement);
            if (results) {
                if (this._refreshCancellationSource.token.isCancellationRequested) {
                    children = undefined;
                }
                else {
                    children = results;
                }
            }
            else {
                children = undefined;
            }
        }
        if (!cachedElement) {
            this.roots = children;
        }
        else {
            this.nodes.set(cachedElement, children);
        }
        return children;
    }
    /**
     * 将 treeItem 转换为 TreeViewItem 以便序列化处理
     * @param treeItem
     * @param props 额外追加的字段
     * @returns
     */
    toTreeViewItem(treeItem, props) {
        const { id, label, iconPath } = treeItem;
        let icon;
        let iconUrl;
        let themeIcon;
        if (typeof iconPath === 'string' && iconPath.indexOf('fa-') !== -1) {
            icon = iconPath;
        }
        else if (iconPath instanceof types.ThemeIcon) {
            themeIcon = iconPath;
        }
        else {
            const light = this.getLightIconPath(treeItem);
            const dark = this.getDarkIconPath(treeItem) || light;
            if (light) {
                iconUrl = {
                    dark,
                    light,
                };
            }
        }
        let checkboxInfo;
        if ((0, ide_core_common_1.isUndefined)(treeItem.checkboxState)) {
            checkboxInfo = undefined;
        }
        else if (!(0, ide_core_common_1.isNumber)(treeItem.checkboxState)) {
            checkboxInfo = {
                checked: treeItem.checkboxState.state === vscode_1.TreeItemCheckboxState.Checked,
                tooltip: treeItem.checkboxState.tooltip,
                accessibilityInformation: treeItem.checkboxState.accessibilityInformation,
            };
        }
        else {
            checkboxInfo = {
                checked: treeItem.checkboxState === vscode_1.TreeItemCheckboxState.Checked,
            };
        }
        const treeViewItem = {
            id,
            label,
            icon,
            iconUrl,
            themeIcon,
            description: treeItem.description,
            resourceUri: treeItem.resourceUri,
            tooltip: treeItem.tooltip,
            collapsibleState: treeItem.collapsibleState,
            contextValue: treeItem.contextValue,
            checkboxInfo,
            accessibilityInformation: treeItem.accessibilityInformation,
            command: treeItem.command ? this.commands.converter.toInternal(treeItem.command, this.disposable) : undefined,
            ...props,
        };
        return treeViewItem;
    }
    async onExpanded(treeItemId) {
        // 从缓存中获取节点
        const cachedElement = this.getTreeItem(treeItemId);
        // 触发展开事件
        if (cachedElement) {
            this.onDidExpandElementEmitter.fire({
                element: cachedElement,
            });
        }
    }
    async onCollapsed(treeItemId) {
        const cachedElement = this.getTreeItem(treeItemId);
        // 触发折叠事件
        if (cachedElement) {
            this.onDidCollapseElementEmitter.fire({
                element: cachedElement,
            });
        }
    }
    getDarkIconPath(extensionTreeItem) {
        if (extensionTreeItem.iconPath &&
            !(extensionTreeItem.iconPath instanceof types.ThemeIcon) &&
            extensionTreeItem.iconPath.dark) {
            return this.getIconPath(extensionTreeItem.iconPath.dark);
        }
        return undefined;
    }
    getLightIconPath(extensionTreeItem) {
        if (extensionTreeItem.iconPath && !(extensionTreeItem.iconPath instanceof types.ThemeIcon)) {
            if (typeof extensionTreeItem.iconPath === 'string' || ide_core_common_1.Uri.isUri(extensionTreeItem.iconPath)) {
                return this.getIconPath(extensionTreeItem.iconPath);
            }
            return this.getIconPath(extensionTreeItem.iconPath.light);
        }
        return undefined;
    }
    getIconPath(iconPath) {
        if (ide_core_common_1.Uri.isUri(iconPath)) {
            if (/^http(s)?/.test(iconPath.scheme)) {
                return iconPath.toString();
            }
            else if (/^image/.test(iconPath.path.toString())) {
                return `data:${iconPath.fsPath.toString()}`;
            }
            return iconPath.with({ scheme: '' }).toString();
        }
        return iconPath;
    }
    setVisible(visible) {
        if (visible !== this._visible) {
            this._visible = visible;
            this.onDidChangeVisibilityEmitter.fire(Object.freeze({ visible: this._visible }));
        }
    }
    setSelection(selectedItemIds) {
        this.doSetSelection(selectedItemIds);
    }
    doSetSelection(selectedItemIts) {
        this.selectedItemIds = new Set(selectedItemIts);
        this.onDidChangeSelectionEmitter.fire(Object.freeze({ selection: this.selectedElements }));
    }
}
//# sourceMappingURL=ext.host.treeview.js.map