"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const vscode = __importStar(require("vscode-languageserver-protocol"));
const getUserPreferences_1 = require("../configs/getUserPreferences");
const shared_1 = require("../shared");
function register(ctx) {
    const ts = ctx.typescript.module;
    return async (uri, range) => {
        const document = ctx.getTextDocument(uri);
        if (!document)
            return;
        const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
        const fileName = ctx.uriToFileName(document.uri);
        const start = document.offsetAt(range.start);
        const end = document.offsetAt(range.end);
        const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.typescript.languageService
            ? ctx.typescript.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
            : []) ?? [];
        return inlayHints.map(inlayHint => {
            const result = vscode.InlayHint.create(document.positionAt(inlayHint.position), inlayHint.text, inlayHint.kind === ts.InlayHintKind.Type ? vscode.InlayHintKind.Type
                : inlayHint.kind === ts.InlayHintKind.Parameter ? vscode.InlayHintKind.Parameter
                    : undefined);
            result.paddingLeft = inlayHint.whitespaceBefore;
            result.paddingRight = inlayHint.whitespaceAfter;
            return result;
        });
    };
}
exports.register = register;
//# sourceMappingURL=inlayHints.js.map