import { isDiagnosticWithLocation, convertTSDiagnosticToCM } from './utils.js';

/**
 * Lower-level interface to get semantic and syntactic
 * diagnostics from the TypeScript environment.
 *
 * This is used by tsLinter and tsLinterWorker,
 * but you can use it directly to power other UI.
 */
function getLints({ env, path, diagnosticCodesToIgnore, }) {
    // Don't crash if the relevant file isn't created yet.
    const exists = env.getSourceFile(path);
    if (!exists)
        return [];
    const syntaticDiagnostics = env.languageService.getSyntacticDiagnostics(path);
    const semanticDiagnostics = env.languageService.getSemanticDiagnostics(path);
    const diagnostics = [...syntaticDiagnostics, ...semanticDiagnostics].filter((diagnostic) => isDiagnosticWithLocation(diagnostic) &&
        !diagnosticCodesToIgnore.includes(diagnostic.code));
    return diagnostics.map(convertTSDiagnosticToCM);
}

export { getLints };
