"use strict";
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.markerFixKey = markerFixKey;
exports.setModelFixes = setModelFixes;
exports.getModelFix = getModelFix;
exports.clearModelFixes = clearModelFixes;
exports.setModelSyntaxFixes = setModelSyntaxFixes;
exports.getModelSyntaxFix = getModelSyntaxFix;
exports.clearModelSyntaxFixes = clearModelSyntaxFixes;
// Shared via globalThis so that, even when osd-monaco is bundled more than once,
// the writer (language.ts) and reader (code_action_provider.ts) see one table.
const FIX_REGISTRY_KEY = '__osdPPLLintFixRegistry';
function getState() {
    const globalScope = globalThis;
    if (!globalScope[FIX_REGISTRY_KEY]) {
        globalScope[FIX_REGISTRY_KEY] = { byModel: new WeakMap(), syntaxByModel: new WeakMap() };
    }
    const state = globalScope[FIX_REGISTRY_KEY];
    // Back-fill the syntax table on a registry created by an older bundle.
    if (!state.syntaxByModel) {
        state.syntaxByModel = new WeakMap();
    }
    return state;
}
// Stable key correlating a stored fix with a marker after the marker has
// round-tripped through Monaco's MarkerService (position + message survive).
function markerFixKey(marker) {
    return [
        marker.startLineNumber,
        marker.startColumn,
        marker.endLineNumber,
        marker.endColumn,
        marker.message,
    ].join(':');
}
// Replace the lint fix table for a model. An empty map clears the entry so
// stale fixes never outlive the markers they belong to.
function setModelFixes(model, fixes) {
    if (fixes.size === 0) {
        getState().byModel.delete(model);
        return;
    }
    getState().byModel.set(model, fixes);
}
function getModelFix(model, key) {
    return getState().byModel.get(model)?.get(key);
}
function clearModelFixes(model) {
    getState().byModel.delete(model);
}
// Replace the syntax-error fix table for a model (owner PPL_WORKER), parallel to
// setModelFixes. An empty map clears the entry.
function setModelSyntaxFixes(model, fixes) {
    if (fixes.size === 0) {
        getState().syntaxByModel.delete(model);
        return;
    }
    getState().syntaxByModel.set(model, fixes);
}
function getModelSyntaxFix(model, key) {
    return getState().syntaxByModel.get(model)?.get(key);
}
function clearModelSyntaxFixes(model) {
    getState().syntaxByModel.delete(model);
}
//# sourceMappingURL=fix_registry.js.map