# 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
class ErrorsHighlighter(object):

    # Constants
    underline = sublime.DRAW_SQUIGGLY_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE


    def __init__(self, project):
        self.project = project
        self._icon_paths()


    def _icon_paths(self):
        """ defines paths for icons """
        if os.name == 'nt':
            self.error_icon = ".."+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-illegal')
            self.warning_icon = ".."+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-warning')
        else:
            self.error_icon = "Packages"+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-illegal.png')
            self.warning_icon = "Packages"+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-warning.png')


    @max_calls(name='Errors.highlight')
    def highlight_all_open_files(self):
        """ update hightlights (red underline) in all files, using the errors in project """

        self.errors = {}

        # iterate through all open views, to remove all remaining outdated underlinings
        for window in sublime.windows():
            for view in window.views():

# 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

class ErrorsHighlighter(object):

    # Constants
    underline = sublime.DRAW_SQUIGGLY_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_EMPTY_AS_OVERWRITE


    def __init__(self, project):
        self.project = project
        self._icon_paths()


    def _icon_paths(self):
        """ defines paths for icons """
        if os.name == 'nt':
            self.error_icon = ".."+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-illegal')
            self.warning_icon = ".."+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-warning')
        else:
            self.error_icon = "Packages"+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-illegal.png')
            self.warning_icon = "Packages"+os.path.join(package_path.split('Packages')[1], 'icons', 'bright-warning.png')


    @max_calls(name='Errors.highlight')
    def highlight_all_open_files(self):
        """ update hightlights (red underline) in all files, using the errors in project """

        self.errors = {}

        # iterate through all open views, to remove all remaining outdated underlinings
        for window in sublime.windows():
            for view in window.views():

                if is_ts(view):