import { linter } from '../../../../../../@codemirror_lint@6.8.1/node_modules/@codemirror/lint/dist/index.js';
import { tsFacet } from '../facet/tsFacet.js';
import { getLints } from './getLints.js';
import { Annotation } from '../../../../../../@codemirror_state@6.5.2/node_modules/@codemirror/state/dist/index.js';

/**
 * An annotation that you can send to CodeMirror to cause the code
 * to be re-linted. This could be because you've updated stuff
 * out-of-band in the TypeScript environment.
 *
 * @example
 * view.dispatch({
 *   annotations: [triggerLint.of(true)],
 * });
 */
const triggerLint = Annotation.define();
/**
 * Binds the TypeScript `lint()` method with TypeScript's
 * semantic and syntactic diagnostics. You can use
 * the `getLints` method for a lower-level interface
 * to the same data.
 */
function tsLinter({ diagnosticCodesToIgnore, } = {}) {
    return linter(async (view) => {
        const config = view.state.facet(tsFacet);
        return config?.env
            ? getLints({
                ...config,
                diagnosticCodesToIgnore: diagnosticCodesToIgnore || [],
            })
            : [];
    }, {
        needsRefresh: (update) => {
            return update.transactions.some((tr) => tr.annotation(triggerLint));
        },
    });
}

export { triggerLint, tsLinter };
