"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HoverAdapter = void 0;
const tslib_1 = require("tslib");
const Converter = tslib_1.__importStar(require("../../../../common/vscode/converter"));
const ext_types_1 = require("../../../../common/vscode/ext-types");
class HoverAdapter {
    constructor(provider, documents) {
        this.provider = provider;
        this.documents = documents;
    }
    provideHover(resource, position, token) {
        const documentData = this.documents.getDocumentData(resource.toString());
        if (!documentData) {
            return Promise.reject(new Error(`There are no document for ${resource}`));
        }
        const pos = Converter.toPosition(position);
        const doc = documentData.document;
        return Promise.resolve(this.provider.provideHover(doc, pos, token)).then((value) => {
            if (!value || !Array.isArray(value.contents) || value.contents.length === 0) {
                return undefined;
            }
            if (!value.range) {
                value.range = doc.getWordRangeAtPosition(pos);
            }
            if (!value.range) {
                value.range = new ext_types_1.Range(pos, pos);
            }
            return Converter.fromHover(value);
        });
    }
}
exports.HoverAdapter = HoverAdapter;
//# sourceMappingURL=hover.js.map