# Path: lib/utils/debug.py
# def max_calls(limit = 1500, name=""):
#     """Decorator which allows its wrapped function to be called `limit` times"""
#     def decorator(func):
#         # Disable limit:
#         return func
#         @wraps(func)
#         def wrapper(*args, **kwargs):
#             calls = getattr(wrapper, 'calls', 0)
#             calls += 1
#             setattr(wrapper, 'calls', calls)
#             fname = name if name != "" else func.__name__
# 
#             if calls == limit + 1:
#                 Debug('max_calls', "LIMIT !! ## !!: Fkt %s has %i calls, stop" % (fname, calls - 1))
# 
#             if calls >= limit + 1:
#                 return None
# 
#             Debug('max_calls', "CALL: Fkt %s has %i calls -> +1" % (fname, calls - 1))
# 
#             return func(*args, **kwargs)
#         setattr(wrapper, 'calls', 0)
#         return wrapper
#     return decorator
# 
# Path: lib/utils/pathutils.py
# def add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# Path: lib/utils/fileutils.py
# def fn2k(filename):
#     """ shortcut for filename2key """
#     return filename2key(filename)
# 
# def is_ts(view):
#     if view is None:
#         return False
#     fn = view.file_name()
#     fn2 = view.file_name()
#     fn3 = view.file_name()
#     if fn is None or fn2 is None:
#         return False
#     if fn is None or fn2 is None or fn3 is None:
#         pass
#         #import spdb ; spdb.start()
#     return fn.endswith('.ts') and not fn.endswith('.d.ts')


from threading import Thread
from ..utils import package_path, max_calls
from ..utils.fileutils import fn2k, is_ts
import sublime
import os
import json

                    # apply regions, even if empty (that will remove every highlight in that file)
                    view.add_regions('typescript-error' , error_regions , 'invalid' , self.error_icon, self.underline)
                    view.add_regions('typescript-warnings' , warning_regions , 'invalid' , self.warning_icon, self.underline)


    previously_error_under_cursor = False

    @max_calls(name='ErrorHighlighter.display_error_in_status_if_cursor')
    def display_error_in_status_if_cursor(self, view):
        """
            Displays the error message in the sublime status
            line if the cursor is above an error (in source code).
            For the click on the error list, see T3SVIEWS.ERROR.on_click()
        """
        try:
            error = self._get_error_at(view.sel()[0].begin(), view.file_name())
        except:
            # no selection in view
            return
        if error is not None:
            sublime.status_message(error)
            self.previously_error_under_cursor = True
        elif self.previously_error_under_cursor: # only clear once
            sublime.status_message('')
            self.previously_error_under_cursor = False


    def _get_error_at(self, pos, filename):
        """ Returns the error at pos in filename """

# Path: lib/utils/debug.py
# def max_calls(limit = 1500, name=""):
#     """Decorator which allows its wrapped function to be called `limit` times"""
#     def decorator(func):
#         # Disable limit:
#         return func
#         @wraps(func)
#         def wrapper(*args, **kwargs):
#             calls = getattr(wrapper, 'calls', 0)
#             calls += 1
#             setattr(wrapper, 'calls', calls)
#             fname = name if name != "" else func.__name__
# 
#             if calls == limit + 1:
#                 Debug('max_calls', "LIMIT !! ## !!: Fkt %s has %i calls, stop" % (fname, calls - 1))
# 
#             if calls >= limit + 1:
#                 return None
# 
#             Debug('max_calls', "CALL: Fkt %s has %i calls -> +1" % (fname, calls - 1))
# 
#             return func(*args, **kwargs)
#         setattr(wrapper, 'calls', 0)
#         return wrapper
#     return decorator
# 
# Path: lib/utils/pathutils.py
# def add_usr_local_bin_to_path_on_osx():
# def find_tsconfigdir(rootdir):
# def expand_variables(path, project=None, use_cache=False):
# def get_tss_path():
# def get_expandglob_path():
# def default_node_path(node_path, project=None):
# def default_tsc_path(tsc_path=None, project=None):
# def search_node_modules(rootdir):
# 
# Path: lib/utils/fileutils.py
# def fn2k(filename):
#     """ shortcut for filename2key """
#     return filename2key(filename)
# 
# def is_ts(view):
#     if view is None:
#         return False
#     fn = view.file_name()
#     fn2 = view.file_name()
#     fn3 = view.file_name()
#     if fn is None or fn2 is None:
#         return False
#     if fn is None or fn2 is None or fn3 is None:
#         pass
#         #import spdb ; spdb.start()
#     return fn.endswith('.ts') and not fn.endswith('.d.ts')


# Path: lib/system/ErrorsHighlighter.py
from threading import Thread
from ..utils import package_path, max_calls
from ..utils.fileutils import fn2k, is_ts
import sublime
import os
import json


                    # apply regions, even if empty (that will remove every highlight in that file)
                    view.add_regions('typescript-error' , error_regions , 'invalid' , self.error_icon, self.underline)
                    view.add_regions('typescript-warnings' , warning_regions , 'invalid' , self.warning_icon, self.underline)


    previously_error_under_cursor = False

    @max_calls(name='ErrorHighlighter.display_error_in_status_if_cursor')
    def display_error_in_status_if_cursor(self, view):
        """
            Displays the error message in the sublime status
            line if the cursor is above an error (in source code).
            For the click on the error list, see T3SVIEWS.ERROR.on_click()
        """
        try:
            error = self._get_error_at(view.sel()[0].begin(), view.file_name())
        except:
            # no selection in view
            return
        if error is not None:
            sublime.status_message(error)
            self.previously_error_under_cursor = True
        elif self.previously_error_under_cursor: # only clear once
            sublime.status_message('')
            self.previously_error_under_cursor = False


    def _get_error_at(self, pos, filename):
        """ Returns the error at pos in filename """

        if fn2k(filename) in self.errors: