"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 async (uri, token = vscode.CancellationToken.None) => {
        return await (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], async (plugin, document) => {
            if (token.isCancellationRequested)
                return;
            let codeLens = await plugin.provideCodeLenses?.(document, token);
            const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
            codeLens?.forEach(codeLens => {
                codeLens.data = {
                    kind: 'normal',
                    uri,
                    original: {
                        data: codeLens.data,
                    },
                    pluginId,
                };
            });
            const ranges = await plugin.provideReferencesCodeLensRanges?.(document, token);
            const referencesCodeLens = ranges?.map(range => vscode.CodeLens.create(range, {
                kind: 'references',
                uri,
                range,
                pluginId,
            }));
            codeLens = [
                ...codeLens ?? [],
                ...referencesCodeLens ?? [],
            ];
            return codeLens;
        }, (data, map) => data.map(codeLens => {
            if (!map)
                return codeLens;
            const range = map.toSourceRange(codeLens.range);
            if (range) {
                return {
                    ...codeLens,
                    range,
                };
            }
        }).filter(common_1.notEmpty), arr => arr.flat()) ?? [];
    };
}
exports.register = register;
//# sourceMappingURL=codeLens.js.map