# Path: lib/system/busted/Liste.py
# def get_root(self,filename):
#     """ return <root filename> of file <filename> or None """
#     if not filename or not self.has(filename):
#         return None
#     return self.liste[fn2k(filename)]['root']


import sublime
import sys
import os
from .Liste import get_root
from ..Utils import read_and_decode_json_file, read_file, get_any_ts_view, fn2l, get_any_view_with_root
    def __init__(self):
        super(Settings, self).__init__()


    def get(self, token, root):
        return self.projects_type[root].get(get_any_view_with_root(root),token)


    def get_root(self, view):
        if view.file_name() == None: return 'no_ts'
        project_settings = view.settings().get('typescript')
        current_folder = os.path.dirname(view.file_name())
        top_folder =  self.get_top_folder(current_folder)
        top_folder_segments = top_folder.split(os.sep)
        has_project_settings = project_settings != None and hasattr(project_settings, 'get')

        # DO WE HAVE ROOT FILES DEFINED INSIDE THE PROJECT FILE
        if has_project_settings:
            roots = project_settings.get('roots')
            for root in roots:
                root_path = os.sep.join(top_folder_segments[:] + fn2l(root).split('/'))
                root_top_folder = self.get_top_folder(os.path.dirname(root_path))
                if current_folder.lower().startswith(root_top_folder.lower()):
                    if root_path not in self.projects_type:
                        #TODOself.projects_type[root_path] = ProjectSettings(SUBLIME_PROJECT)
                        pass
                    return root_path

        # PROJECT SETTINGS BUT NO ROOTS INSIDE > DO WE HAVE A SUBLIMETS FILE ?
        segments = current_folder.split(os.sep)

# Path: lib/system/busted/Liste.py
# def get_root(self,filename):
#     """ return <root filename> of file <filename> or None """
#     if not filename or not self.has(filename):
#         return None
#     return self.liste[fn2k(filename)]['root']


# Path: lib/system/busted/Settings.py
import sublime
import sys
import os
from .Liste import get_root
from ..Utils import read_and_decode_json_file, read_file, get_any_ts_view, fn2l, get_any_view_with_root

    def __init__(self):
        super(Settings, self).__init__()


    def get(self, token, root):
        return self.projects_type[root].get(get_any_view_with_root(root),token)


    def get_root(self, view):
        if view.file_name() == None: return 'no_ts'
        project_settings = view.settings().get('typescript')
        current_folder = os.path.dirname(view.file_name())
        top_folder =  self.get_top_folder(current_folder)
        top_folder_segments = top_folder.split(os.sep)
        has_project_settings = project_settings != None and hasattr(project_settings, 'get')

        # DO WE HAVE ROOT FILES DEFINED INSIDE THE PROJECT FILE
        if has_project_settings:
            roots = project_settings.get('roots')
            for root in roots:
                root_path = os.sep.join(top_folder_segments[:] + fn2l(root).split('/'))
                root_top_folder = self.get_top_folder(os.path.dirname(root_path))
                if current_folder.lower().startswith(root_top_folder.lower()):
                    if root_path not in self.projects_type:
                        #TODOself.projects_type[root_path] = ProjectSettings(SUBLIME_PROJECT)
                        pass
                    return root_path

        # PROJECT SETTINGS BUT NO ROOTS INSIDE > DO WE HAVE A SUBLIMETS FILE ?
        segments = current_folder.split(os.sep)

        segments[0] = top_folder.split(os.sep)[0]