"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceAdapter = void 0;
const tslib_1 = require("tslib");
const Converter = tslib_1.__importStar(require("../../../../common/vscode/converter"));
const utils_1 = require("../../../../common/vscode/utils");
class ReferenceAdapter {
    constructor(provider, documents) {
        this.provider = provider;
        this.documents = documents;
    }
    provideReferences(resource, position, context, token) {
        const documentData = this.documents.getDocumentData(resource);
        if (!documentData) {
            return Promise.reject(new Error(`There is no document for ${resource}`));
        }
        const document = documentData.document;
        const zeroBasedPosition = Converter.toPosition(position);
        return Promise.resolve(this.provider.provideReferences(document, zeroBasedPosition, context, token)).then((reference) => {
            if (!reference) {
                return undefined;
            }
            if ((0, utils_1.isLocationArray)(reference)) {
                const locations = [];
                for (const location of reference) {
                    locations.push(Converter.fromLocation(location));
                }
                return locations;
            }
        });
    }
}
exports.ReferenceAdapter = ReferenceAdapter;
//# sourceMappingURL=reference.js.map