# Path: lib/system/busted/Liste.py
# LISTE = Liste()


from threading import Thread
from ..Utils import read_file, file_exists, fn2l, Debug, max_calls
from ..Tss import TSS
from .Liste import LISTE
import sublime
import re
import os

class Files(object):
    """
        Keeps track of the files TSS uses (currently?).
        Keeps references like this /// <reference path="lib/mocha/mocha.d.ts" />
        up to date. For this it parses unsaved views after each keystroke.
    """

    @max_calls(name='Files.init')
    def init(self, root, callback):
        self.update_indexed_files(root, callback)

    @max_calls(name='Files.update_indexed_files')
    def update_indexed_files(self, root, callback=None):
        """ add the files in current project (=root) determined by tss>files command to LISTE """
        def async_react(files):
            """ callback for async tss>files response. Add files"""
            for f in files:
                self.add(root, f)
            if callback is not None:
                callback()
        Debug('files', "GETTING FILE LIST from TSS")
        TSS.get_tss_indexed_files(root, async_react)


    @max_calls(name='Files.add')
    def add(self, root, filename):
        """ Adds/updates filename in LISTE, keeping track of belonging project (=root) and references """
        Debug('files', "ADD FILE to LISTE, parse references: %s" % filename)


# Path: lib/system/busted/Liste.py
# LISTE = Liste()


# Path: lib/system/busted/Files.py
from threading import Thread
from ..Utils import read_file, file_exists, fn2l, Debug, max_calls
from ..Tss import TSS
from .Liste import LISTE
import sublime
import re
import os


class Files(object):
    """
        Keeps track of the files TSS uses (currently?).
        Keeps references like this /// <reference path="lib/mocha/mocha.d.ts" />
        up to date. For this it parses unsaved views after each keystroke.
    """

    @max_calls(name='Files.init')
    def init(self, root, callback):
        self.update_indexed_files(root, callback)

    @max_calls(name='Files.update_indexed_files')
    def update_indexed_files(self, root, callback=None):
        """ add the files in current project (=root) determined by tss>files command to LISTE """
        def async_react(files):
            """ callback for async tss>files response. Add files"""
            for f in files:
                self.add(root, f)
            if callback is not None:
                callback()
        Debug('files', "GETTING FILE LIST from TSS")
        TSS.get_tss_indexed_files(root, async_react)


    @max_calls(name='Files.add')
    def add(self, root, filename):
        """ Adds/updates filename in LISTE, keeping track of belonging project (=root) and references """
        Debug('files', "ADD FILE to LISTE, parse references: %s" % filename)


        LISTE.add(filename,