<commit_before>from subprocess import Popen, PIPE
from os import path
import string
import tempfile
import unittest
import json
import threading
import hidewin
import vim

class G:
    fsac = None
    fsi = None
    paths = {}
    locations = []
    projects = {}

class Interaction:
    def __init__(self, proc, timeOut, logfile = None):
        self.data = None
        self.event = threading.Event()
        self.proc = proc
        self._timeOut = timeOut
        self.logfile = logfile
        self.debug = not logfile is None

    def _write(self, txt):
        self.proc.stdin.write(txt)

        if self.debug:
            self.logfile.write("> " + txt)
            self.logfile.flush()

    def read(self):
        self.event.wait(self._timeOut)
        if self.debug:
            self.logfile.write('msg received %s\n' % self.data)
        return self.data

    def send(self, command):
        self.data = None
        self.event.clear()
        self._write(command)
        return self.read()

    def send_async(self, command):
        self.data = None
        self.event.clear()
        self._write(command)

    # only on worker thread
    def update(self, data):
        self.data = data
        self.event.set()

class FSAutoComplete:
    def __init__(self, dir, debug = False):
        if debug:
            self.logfiledir = tempfile.gettempdir() + "/log.txt"
            self.logfile = open(self.logfiledir, "w")
        else:
            self.logfile = None

        command = ['mono', dir + '/bin/fsautocomplete.exe']
        opts = { 'stdin': PIPE, 'stdout': PIPE, 'stderr': PIPE, 'universal_newlines': True }
        hidewin.addopt(opts)
        try:
            self.p = Popen(command, **opts)
        except WindowsError:
            self.p = Popen(command[1:], **opts)

        self.debug = debug
        self.switch_to_json()

        self.completion = Interaction(self.p, 3, self.logfile)<commit_msg>Give helpful error if fsautocomplete.exe not found<commit_after>from subprocess import Popen, PIPE
from os import path
import string
import tempfile
import unittest
import json
import threading
import hidewin
import vim

class G:
    fsac = None
    fsi = None
    paths = {}
    locations = []
    projects = {}

class Interaction:
    def __init__(self, proc, timeOut, logfile = None):
        self.data = None
        self.event = threading.Event()
        self.proc = proc
        self._timeOut = timeOut
        self.logfile = logfile
        self.debug = not logfile is None

    def _write(self, txt):
        self.proc.stdin.write(txt)

        if self.debug:
            self.logfile.write("> " + txt)
            self.logfile.flush()

    def read(self):
        self.event.wait(self._timeOut)
        if self.debug:
            self.logfile.write('msg received %s\n' % self.data)
        return self.data

    def send(self, command):
        self.data = None
        self.event.clear()
        self._write(command)
        return self.read()

    def send_async(self, command):
        self.data = None
        self.event.clear()
        self._write(command)

    # only on worker thread
    def update(self, data):
        self.data = data
        self.event.set()

class FSAutoComplete:
    def __init__(self, dir, debug = False):
        if debug:
            self.logfiledir = tempfile.gettempdir() + "/log.txt"
            self.logfile = open(self.logfiledir, "w")
        else:
            self.logfile = None

        command = ['mono', dir + '/bin/fsautocomplete.exe']
        opts = { 'stdin': PIPE, 'stdout': PIPE, 'stderr': PIPE, 'universal_newlines': True }
        hidewin.addopt(opts)
        try:
            self.p = Popen(command, **opts)
        except WindowsError:
            try:
                self.p = Popen(command[1:], **opts)
            except WindowsError as error:
                msg = "Windows Error encountered while trying to execute %s: %s" % (command[1:], error)
                raise WindowsError(msg)

        self.debug = debug
        self.switch_to_json()

        self.completion = Interaction(self.p, 3, self.logfile)
{'fraction_non_alphanumeric': 0.11019015114578254, 'fraction_numerical': 0.0012189176011701609, 'mean_word_length': 2.005860805860806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5769133', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1224, 'n_words': 322}