# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/CancelCommand.py
# def catch_CancelCommand(func):
#     """ Decorate every command with this one. It will check for
#         the plugin disabled flag and catch CancelCommand exceptins. """
# 
#     def catcher(*kargs, **kwargs):
#         if is_plugin_temporarily_disabled():
#             return # do not execute command
#         try:
#             return func(*kargs, **kwargs)
#         except CancelCommand:
#             Debug('command', "A COMMAND WAS CANCELED")
#             return False
#     return catcher
# 
# class CancelCommand(Exception):
#     """ Throw this exception in a command. The decorator
#         catch_CancelCommand will catch it and cancel silently """
#     pass
# 
# Path: lib/utils/fileutils.py
# def read_file(filename):
#     """ returns None or file contents if available """
#     filename = os.path.normcase(filename) # back to \\ in nt
#     if os.path.isfile(filename):
#         try:
#             if os.name == 'nt':
#                 return open(filename, 'r', encoding='utf8').read()
#             else:
#                 return codecs.open(filename, 'r', 'utf-8').read()
#         except IOError:
#             pass
#     return None
# 
# 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/viewutils.py
# def get_content(view):
#     return view.substr(sublime.Region(0, view.size()))
# 
# Path: lib/utils/options.py

# 
# Path: lib/utils/disabling.py
# def set_tsglobexpansion_disabled():
#     """ Sets the disabled flag for tsglobexpansion """
#     if "*tsglob" not in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.append("*tsglob")
# 
# def set_tsglobexpansion_enabled():
#     """ Clears the disabled flag for tsglobexpansion """
#     if "*tsglob" in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.remove("*tsglob")
# 
# def is_tsglobexpansion_disabled():
#     """ Checks the disabled flag for tsglobexpansion """
#     return "*tsglob"  in plugin_disabled_for_folders


import sublime
import json
import os
import re
from ..utils.debug import Debug
from ..utils.CancelCommand import catch_CancelCommand, CancelCommand
from ..utils.fileutils import read_file
from ..utils.pathutils import package_path
from ..utils.viewutils import get_content
from ..utils.options import allowed_compileroptions, \
                            allowed_settings, \
                             compileroptions_validations, \
                             settings_validations
from ..utils.disabling import set_tsglobexpansion_disabled, \
                              set_tsglobexpansion_enabled, \
                              is_tsglobexpansion_disabled
            raise CancelCommand()


    def _check_empty_and_insert_default(self):
        """ Checks if content is empty and inserts default tsonfig.json if so.
            Raises CancelCommand() if empty before. """

        if self.content == "":
            if not is_tsglobexpansion_disabled() and self.view:
                Debug('tsconfig', 'put default base structure to tsconfig.json')
                self.view.run_command('append', {'characters':
                        json.dumps(empty_tsconfig, indent=4)})
            raise CancelCommand()


    # ######################################################################
    # ###############                   JSON                      ##########
    # ######################################################################


    def _check_jsonsyntax(self):
        """ Parse self.content into self.tsconfig.
            Raise CancelCommand on Fatal Error.
            Make HardErrors on syntax errors.
            Return True if parsing has succeeded, even if there were errors. """

        try:
            # DECODE
            self.tsconfig = json.loads(self.content)
        except ValueError as e:

# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/CancelCommand.py
# def catch_CancelCommand(func):
#     """ Decorate every command with this one. It will check for
#         the plugin disabled flag and catch CancelCommand exceptins. """
# 
#     def catcher(*kargs, **kwargs):
#         if is_plugin_temporarily_disabled():
#             return # do not execute command
#         try:
#             return func(*kargs, **kwargs)
#         except CancelCommand:
#             Debug('command', "A COMMAND WAS CANCELED")
#             return False
#     return catcher
# 
# class CancelCommand(Exception):
#     """ Throw this exception in a command. The decorator
#         catch_CancelCommand will catch it and cancel silently """
#     pass
# 
# Path: lib/utils/fileutils.py
# def read_file(filename):
#     """ returns None or file contents if available """
#     filename = os.path.normcase(filename) # back to \\ in nt
#     if os.path.isfile(filename):
#         try:
#             if os.name == 'nt':
#                 return open(filename, 'r', encoding='utf8').read()
#             else:
#                 return codecs.open(filename, 'r', 'utf-8').read()
#         except IOError:
#             pass
#     return None
# 
# 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/viewutils.py
# def get_content(view):
#     return view.substr(sublime.Region(0, view.size()))
# 
# Path: lib/utils/options.py

# 
# Path: lib/utils/disabling.py
# def set_tsglobexpansion_disabled():
#     """ Sets the disabled flag for tsglobexpansion """
#     if "*tsglob" not in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.append("*tsglob")
# 
# def set_tsglobexpansion_enabled():
#     """ Clears the disabled flag for tsglobexpansion """
#     if "*tsglob" in plugin_disabled_for_folders:
#         plugin_disabled_for_folders.remove("*tsglob")
# 
# def is_tsglobexpansion_disabled():
#     """ Checks the disabled flag for tsglobexpansion """
#     return "*tsglob"  in plugin_disabled_for_folders


# Path: lib/tsconfiglint/TsconfigLinter.py
import sublime
import json
import os
import re
from ..utils.debug import Debug
from ..utils.CancelCommand import catch_CancelCommand, CancelCommand
from ..utils.fileutils import read_file
from ..utils.pathutils import package_path
from ..utils.viewutils import get_content
from ..utils.options import allowed_compileroptions, \
                            allowed_settings, \
                             compileroptions_validations, \
                             settings_validations
from ..utils.disabling import set_tsglobexpansion_disabled, \
                              set_tsglobexpansion_enabled, \
                              is_tsglobexpansion_disabled

            raise CancelCommand()


    def _check_empty_and_insert_default(self):
        """ Checks if content is empty and inserts default tsonfig.json if so.
            Raises CancelCommand() if empty before. """

        if self.content == "":
            if not is_tsglobexpansion_disabled() and self.view:
                Debug('tsconfig', 'put default base structure to tsconfig.json')
                self.view.run_command('append', {'characters':
                        json.dumps(empty_tsconfig, indent=4)})
            raise CancelCommand()


    # ######################################################################
    # ###############                   JSON                      ##########
    # ######################################################################


    def _check_jsonsyntax(self):
        """ Parse self.content into self.tsconfig.
            Raise CancelCommand on Fatal Error.
            Make HardErrors on syntax errors.
            Return True if parsing has succeeded, even if there were errors. """

        try:
            # DECODE
            self.tsconfig = json.loads(self.content)
        except ValueError as e:

            Debug('tsconfig', 'json error %s %s' % (type(e), e))