<commit_before>﻿import sublime_plugin

from ..libs.global_vars import *
from ..libs import cli


class TypescriptBuildCommand(sublime_plugin.WindowCommand):
    def run(self):
        if get_node_path() is None:
            print("Cannot find node. Build cancelled.")
            return

        file_name = self.window.active_view().file_name()
        project_info = cli.service.project_info(file_name)
        if project_info["success"]:
            if "configFileName" in project_info["body"]:
                tsconfig_dir = dirname(project_info["body"]["configFileName"])
                self.window.run_command("exec", {
                    "cmd": [get_node_path(), TSC_PATH, "-p", tsconfig_dir],
                    # regex to capture build result for displaying in the output panel
                    "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
                })
            else:
                sublime.active_window().show_input_panel(
                    "Build parameters: ",
                    "",  # initial text
                    lambda params: self.compile_inferred_project(file_name, params),
                    None,  # on change
                    None   # on cancel
                )

    def compile_inferred_project(self, file_name, params=""):
        cmd = [get_node_path(), TSC_PATH, file_name]
        print(cmd)
        if params != "":
            cmd.extend(params.split(' '))
        self.window.run_command("exec", {
            "cmd": cmd,
            "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
        })<commit_msg>Display last build parameters in build dialog.<commit_after>﻿import sublime_plugin

from ..libs.global_vars import *
from ..libs import cli


class TypescriptBuildCommand(sublime_plugin.WindowCommand):
    build_parameters = ""
    
    def run(self):
        if get_node_path() is None:
            print("Cannot find node. Build cancelled.")
            return

        file_name = self.window.active_view().file_name()
        project_info = cli.service.project_info(file_name)
        if project_info["success"]:
            if "configFileName" in project_info["body"]:
                tsconfig_dir = dirname(project_info["body"]["configFileName"])
                self.window.run_command("exec", {
                    "cmd": [get_node_path(), TSC_PATH, "-p", tsconfig_dir],
                    # regex to capture build result for displaying in the output panel
                    "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
                })
            else:
                sublime.active_window().show_input_panel(
                    "Build parameters: ",
                    self.build_parameters,
                    lambda params: self.compile_inferred_project(file_name, params),
                    None,  # on change
                    None   # on cancel
                )

    def compile_inferred_project(self, file_name, params=""):
        cmd = [get_node_path(), TSC_PATH, file_name]
        print(cmd)
        if params != "":
            cmd.extend(params.split(' '))
        self.window.run_command("exec", {
            "cmd": cmd,
            "file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
        })
        self.build_parameters = params
{'fraction_non_alphanumeric': 0.13756940160394818, 'fraction_numerical': 0.0, 'mean_word_length': 1.8077922077922077, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '943077', 'n_tokens_mistral': 944, 'n_tokens_neox': 896, 'n_words': 182}