"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const vscode = require("vscode-languageserver-protocol");
const featureWorkers_1 = require("../utils/featureWorkers");
function register(context) {
    return (uri, position, token = vscode.CancellationToken.None) => {
        return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => {
            if (token.isCancellationRequested)
                return;
            return plugin.provideRenameRange?.(document, position, token);
        }, (item, map) => {
            if (!map) {
                return item;
            }
            if (vscode.Range.is(item)) {
                return map.toSourceRange(item);
            }
            return item;
        }, prepares => {
            for (const prepare of prepares) {
                if (vscode.Range.is(prepare)) {
                    return prepare; // if has any valid range, ignore other errors
                }
            }
            const error = prepares[0];
            const newError = new vscode.ResponseError(error.code, error.message);
            newError.name = error.name;
            newError.stack = error.stack;
            return newError;
        });
    };
}
exports.register = register;
//# sourceMappingURL=renamePrepare.js.map