<commit_before>#include "codechecker.h"
#include "process.h"

CodeChecker::~CodeChecker()
{
    cancel();
}

void CodeChecker::connectSignals()
{
    connect(&p, &MznProcess::started, this, &CodeChecker::onStarted);
    connect(&p, &MznProcess::outputStdOut, this, &CodeChecker::onLine);
    connect(&p, &MznProcess::outputStdError, this, &CodeChecker::onLine);
    connect(&p, &MznProcess::finished, this, &CodeChecker::onFinished);
}

void CodeChecker::start(const QString& modelContents, SolverConfiguration& sc, const QString& wd)
{
    cancel();
    connectSignals();
    inRelevantError = false;
    curError = MiniZincError();
    mznErrors.clear();
    SolverConfiguration checkSc(sc.solverDefinition);
    checkSc.additionalData = sc.additionalData;
    checkSc.extraOptions = sc.extraOptions;
    QStringList args;
    args << "--model-check-only" << "-";
    input = modelContents;
    p.start(checkSc, args, wd);
}

void CodeChecker::cancel()
{
    p.disconnect();
    p.terminate();
}

void CodeChecker::onStarted()
{
    p.writeStdIn(input);
    p.closeStdIn();
}

void CodeChecker::onLine(const QString& l)
{
    QJsonParseError error;
    auto json = QJsonDocument::fromJson(l.toUtf8(), &error);
    if (json.isNull()) {
        return;
    }
    auto msg = json.object();
    if (msg["type"] != "error" && msg["type"] != "warning") {
        return;
    }
    if (!msg["location"].isObject()) {
        return;
    }
    auto loc = msg["location"].toObject();
    MiniZincError e;
    e.isWarning = msg["type"] == "warning";
    e.filename = loc["filename"].toString();
    e.first_line = loc["firstLine"].toInt();
    e.first_col = loc["firstColumn"].toInt();
    e.last_line = loc["lastLine"].toInt();
    e.last_col = loc["lastColumn"].toInt();
    e.msg = msg["message"].toString();
    mznErrors.push_back(e);
}

void CodeChecker::onFinished()
{
    emit finished(mznErrors);
}<commit_msg>Ignore errors in other files during background code checking<commit_after>#include "codechecker.h"
#include "process.h"

CodeChecker::~CodeChecker()
{
    cancel();
}

void CodeChecker::connectSignals()
{
    connect(&p, &MznProcess::started, this, &CodeChecker::onStarted);
    connect(&p, &MznProcess::outputStdOut, this, &CodeChecker::onLine);
    connect(&p, &MznProcess::outputStdError, this, &CodeChecker::onLine);
    connect(&p, &MznProcess::finished, this, &CodeChecker::onFinished);
}

void CodeChecker::start(const QString& modelContents, SolverConfiguration& sc, const QString& wd)
{
    cancel();
    connectSignals();
    inRelevantError = false;
    curError = MiniZincError();
    mznErrors.clear();
    SolverConfiguration checkSc(sc.solverDefinition);
    checkSc.additionalData = sc.additionalData;
    checkSc.extraOptions = sc.extraOptions;
    QStringList args;
    args << "--model-check-only" << "-";
    input = modelContents;
    p.start(checkSc, args, wd);
}

void CodeChecker::cancel()
{
    p.disconnect();
    p.terminate();
}

void CodeChecker::onStarted()
{
    p.writeStdIn(input);
    p.closeStdIn();
}

void CodeChecker::onLine(const QString& l)
{
    QJsonParseError error;
    auto json = QJsonDocument::fromJson(l.toUtf8(), &error);
    if (json.isNull()) {
        return;
    }
    auto msg = json.object();
    if (msg["type"] != "error" && msg["type"] != "warning") {
        return;
    }
    if (!msg["location"].isObject()) {
        return;
    }
    auto loc = msg["location"].toObject();
    MiniZincError e;
    e.isWarning = msg["type"] == "warning";
    e.filename = loc["filename"].toString();
    e.first_line = loc["firstLine"].toInt();
    e.first_col = loc["firstColumn"].toInt();
    e.last_line = loc["lastLine"].toInt();
    e.last_col = loc["lastColumn"].toInt();
    e.msg = msg["message"].toString();
    if (e.filename == "stdin") {
        // Ignore errors that aren't from this file
        mznErrors.push_back(e);
    }
}

void CodeChecker::onFinished()
{
    emit finished(mznErrors);
}
{'fraction_non_alphanumeric': 0.17003027245206861, 'fraction_numerical': 0.0005045408678102926, 'mean_word_length': 3.84718826405868, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7361486', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1335, 'n_words': 244}