"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const featureWorkers_1 = require("../utils/featureWorkers");
const vscode = require("vscode-languageserver-protocol");
const common_1 = require("../utils/common");
function register(context) {
    return (uri, color, range, token = vscode.CancellationToken.None) => {
        return (0, featureWorkers_1.languageFeatureWorker)(context, uri, range, (range, map, file) => {
            if (file.capabilities.documentSymbol) // TODO: add color capability setting
                return map.toGeneratedRanges(range);
            return [];
        }, (plugin, document, range) => {
            if (token.isCancellationRequested)
                return;
            return plugin.provideColorPresentations?.(document, color, range, token);
        }, (data, map) => map ? data.map(cp => {
            if (cp.textEdit) {
                const range = map.toSourceRange(cp.textEdit.range);
                if (!range)
                    return undefined;
                cp.textEdit.range = range;
            }
            if (cp.additionalTextEdits) {
                for (const textEdit of cp.additionalTextEdits) {
                    const range = map.toSourceRange(textEdit.range);
                    if (!range)
                        return undefined;
                    textEdit.range = range;
                }
            }
            return cp;
        }).filter(common_1.notEmpty) : data);
    };
}
exports.register = register;
//# sourceMappingURL=colorPresentations.js.map