<commit_before>package com.reason.bs;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.vfs.VirtualFile;
import com.reason.ide.RmlNotification;
import org.jetbrains.annotations.Nullable;

public class BsCompiler {

    private KillableColoredProcessHandler m_bsb;
    private GeneralCommandLine m_commandLine;
    private ProcessListener m_outputListener;

    BsCompiler(VirtualFile baseDir, String bsbPath) {
        m_commandLine = new GeneralCommandLine(bsbPath, "-no-color", "-make-world");
        m_commandLine.setWorkDirectory(baseDir.getCanonicalPath());
        recreate();
    }

    @Nullable
    public ProcessHandler getHandler() {
        return m_bsb;
    }

    // Wait for the tool window to be ready before starting the process
    public void startNotify() {
        if (m_bsb != null) {
            try {
                m_bsb.startNotify();
            } catch (Throwable e) {
                // already done ?
            }
        }
    }

    @Nullable
    public ProcessHandler recreate() {
        try {
            killIt();
            m_bsb = new KillableColoredProcessHandler(m_commandLine);
            if (m_outputListener != null) {
                m_bsb.addProcessListener(m_outputListener);
            }
            return m_bsb;
        } catch (ExecutionException e) {
            Notifications.Bus.notify(new RmlNotification("Bsb", "Can't run bsb\n" + e.getMessage(), NotificationType.ERROR));
        }

        return null;
    }

    void killIt() {
        if (m_bsb != null) {
            m_bsb.killProcess();
            m_bsb = null;
        }
    }

    public void addListener(ProcessListener outputListener) {
        m_outputListener = outputListener;
        if (m_bsb != null) {
            m_bsb.addProcessListener(outputListener);
        }
    }
}
<commit_msg>Should prevent a runtime error (see #21), but I don't know how to reproduce the problem.<commit_after>package com.reason.bs;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.vfs.VirtualFile;
import com.reason.ide.RmlNotification;
import org.jetbrains.annotations.Nullable;

public class BsCompiler {

    private KillableColoredProcessHandler m_bsb;
    private GeneralCommandLine m_commandLine;
    private ProcessListener m_outputListener;

    BsCompiler(VirtualFile baseDir, String bsbPath) {
        m_commandLine = new GeneralCommandLine(bsbPath, "-no-color", "-make-world");
        m_commandLine.setWorkDirectory(baseDir.getCanonicalPath());
        recreate();
    }

    @Nullable
    public ProcessHandler getHandler() {
        return m_bsb;
    }

    // Wait for the tool window to be ready before starting the process
    public void startNotify() {
        if (m_bsb != null && !m_bsb.isStartNotified()) {
            try {
                m_bsb.startNotify();
            } catch (Throwable e) {
                // already done ?
            }
        }
    }

    @Nullable
    public ProcessHandler recreate() {
        try {
            killIt();
            m_bsb = new KillableColoredProcessHandler(m_commandLine);
            if (m_outputListener != null) {
                m_bsb.addProcessListener(m_outputListener);
            }
            return m_bsb;
        } catch (ExecutionException e) {
            Notifications.Bus.notify(new RmlNotification("Bsb", "Can't run bsb\n" + e.getMessage(), NotificationType.ERROR));
        }

        return null;
    }

    void killIt() {
        if (m_bsb != null) {
            m_bsb.killProcess();
            m_bsb = null;
        }
    }

    public void addListener(ProcessListener outputListener) {
        m_outputListener = outputListener;
        if (m_bsb != null) {
            m_bsb.addProcessListener(outputListener);
        }
    }
}

{'fraction_non_alphanumeric': 0.0911324547688184, 'fraction_numerical': 0.00044672771945499217, 'mean_word_length': 2.593900481540931, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3943832', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1252, 'n_words': 258}