# 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/uiutils.py
# def get_prefix(token):
#     if token in PREFIXES:
#         return PREFIXES[token]
#     else:
#         return ''
# 
# Path: lib/utils/viewutils.py
# def get_file_infos(view):
#     return (view.file_name(), get_lines(view), get_content(view))
# 
# def get_content_of_line_at(view, pos):
#     return view.substr(sublime.Region(view.line(pos-1).a, pos))


import re
import json
import sublime
from ..utils import Debug
from ..utils.uiutils import get_prefix
from ..utils.viewutils import get_file_infos, get_content_of_line_at


    # ENTRY VALUE
    def _get_list_value(self,entry):

        # {'kind': 'method', 'docComment': '', 'kindModifiers': 'declare', 'type': '(method) MSNodeExtensions.swapNode(otherNode: Node): Node', 'name': 'swapNode'}
        # {'kind': 'property', 'docComment': '', 'kindModifiers': 'declare', 'type': '(property) GlobalEventHandlers.onpointerup: (ev: PointerEvent) => any', 'name': 'onpointerup'}
        # {'kind': 'property', 'docComment': '', 'kindModifiers': 'declare', 'type': '(property) Node.DOCUMENT_TYPE_NODE: number', 'name': 'DOCUMENT_TYPE_NODE'}
        # {'kind': 'method', 'docComment': 'Allows updating the print settings for the page.', 'kindModifiers': 'declare', 'type': '(method) Document.updateSettings(): void', 'name': 'updateSettings'}
        # {'kindModifiers': 'declare', 'docComment': '', 'kind': 'function', 'name': 'setTimeout', 'type': '(function) setTimeout(handler: any, timeout?: any, ...args: any[]): number'}

        type_ = entry['type'] if 'type' in entry else entry['name']

        # remove (<kind>)
        kind_part = "(%s)" % entry['kind']
        if type_.startswith(kind_part):
            type_ = type_[len(kind_part):]

        # catches the inner argumetns of a function call
        match = re.match('.*\((.*)\):', str(type_))
        result = []

        if match:
            variables = self._parse_args(match.group(1))
            count = 1
            for variable in variables:
                splits = variable.split(':')
                if len(splits) > 1:
                    data = '"'+variable+'"'
                    data = '${'+str(count)+':'+data+'}'

# 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/uiutils.py
# def get_prefix(token):
#     if token in PREFIXES:
#         return PREFIXES[token]
#     else:
#         return ''
# 
# Path: lib/utils/viewutils.py
# def get_file_infos(view):
#     return (view.file_name(), get_lines(view), get_content(view))
# 
# def get_content_of_line_at(view, pos):
#     return view.substr(sublime.Region(view.line(pos-1).a, pos))


# Path: lib/system/Completion.py
import re
import json
import sublime
from ..utils import Debug
from ..utils.uiutils import get_prefix
from ..utils.viewutils import get_file_infos, get_content_of_line_at



    # ENTRY VALUE
    def _get_list_value(self,entry):

        # {'kind': 'method', 'docComment': '', 'kindModifiers': 'declare', 'type': '(method) MSNodeExtensions.swapNode(otherNode: Node): Node', 'name': 'swapNode'}
        # {'kind': 'property', 'docComment': '', 'kindModifiers': 'declare', 'type': '(property) GlobalEventHandlers.onpointerup: (ev: PointerEvent) => any', 'name': 'onpointerup'}
        # {'kind': 'property', 'docComment': '', 'kindModifiers': 'declare', 'type': '(property) Node.DOCUMENT_TYPE_NODE: number', 'name': 'DOCUMENT_TYPE_NODE'}
        # {'kind': 'method', 'docComment': 'Allows updating the print settings for the page.', 'kindModifiers': 'declare', 'type': '(method) Document.updateSettings(): void', 'name': 'updateSettings'}
        # {'kindModifiers': 'declare', 'docComment': '', 'kind': 'function', 'name': 'setTimeout', 'type': '(function) setTimeout(handler: any, timeout?: any, ...args: any[]): number'}

        type_ = entry['type'] if 'type' in entry else entry['name']

        # remove (<kind>)
        kind_part = "(%s)" % entry['kind']
        if type_.startswith(kind_part):
            type_ = type_[len(kind_part):]

        # catches the inner argumetns of a function call
        match = re.match('.*\((.*)\):', str(type_))
        result = []

        if match:
            variables = self._parse_args(match.group(1))
            count = 1
            for variable in variables:
                splits = variable.split(':')
                if len(splits) > 1:
                    data = '"'+variable+'"'
                    data = '${'+str(count)+':'+data+'}'

                    result.append(data)