"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const transformer = require("../transformer");
const vscode = require("vscode-languageserver-protocol");
function register(context) {
    return async (item, token = vscode.CancellationToken.None) => {
        const data = item.data;
        if (data) {
            const plugin = context.plugins[data.pluginId];
            if (!plugin.resolveCompletionItem)
                return item;
            item = Object.assign(item, data.original);
            if (data.virtualDocumentUri) {
                for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.virtualDocumentUri)) {
                    item = await plugin.resolveCompletionItem(item, token);
                    item = transformer.asCompletionItem(item, embeddedRange => {
                        let range = plugin.resolveEmbeddedRange?.(embeddedRange);
                        if (range)
                            return range;
                        return map.toSourceRange(embeddedRange);
                    }, map.virtualFileDocument);
                }
            }
            else {
                item = await plugin.resolveCompletionItem(item, token);
            }
        }
        // TODO: monkey fix import ts file icon
        if (item.detail !== item.detail + '.ts') {
            item.detail = item.detail;
        }
        return item;
    };
}
exports.register = register;
//# sourceMappingURL=completeResolve.js.map