<commit_before>'''Builds Dart projects intelligently.
'''

import sublime
import sublime_plugin

import os
from functools import partial

from Dart import PluginLogger
from Dart.lib.sdk import SDK
from Dart.lib.dart_project import ViewInspector
from Dart.lib.dart_project import find_pubspec


_logger = PluginLogger(__name__)


class ContextProvider(sublime_plugin.EventListener):
    '''Implements the 'dart_is_project_file' context for .sublime-keymap
    files.
    '''
    def on_query_context(self, view, key, operator, operand, match_all):
        if key == 'dart_is_project_file':
            return ViewInspector(view).is_project_file


class DartBuildProjectCommand(sublime_plugin.WindowCommand):
    '''Orchestrates different build tasks.

    Meant to be called from a key binding.
    '''
    def run(self, action='primary'):
        '''
        @action
          One of: 'primary', 'secondary'
        '''
        view = self.window.active_view()
        if ViewInspector(view).is_pubspec:
            self.window.run_command('dart_build_pubspec', {
                'action': action,
                'file_name': view.file_name()
                })
            return

        self.window.run_command('dart_run', {
            'action': action,
            'file_name': view.file_name()
            })


class AsyncProcessExecutor(object):
    def execute(self, **kwargs):
        self.window.run_command('exec', kwargs)


class DartRunCommand(sublime_plugin.WindowCommand, AsyncProcessExecutor):
    '''Runs a file with the most appropriate action.

    Intended for .dart and .html files.
    '''
    def run(self, file_name, action='primary'):
        '''
        @action
          On of: primary, secondary
        '''
        working_dir = find_pubspec(file_name)
        if not working_dir:
            working_dir = os.path.dirname(file_name)

        sdk = SDK()

        if action == 'primary':
            # TODO(guillermooo): add regexes
            args = {
                    'cmd' : [sdk.path_to_dart2js,
                                '--minify', '-o', file_name + '.js',
                                file_name],
                    'working_dir': working_dir
                    }
            self.execute(**args)
            return

        if action != 'secondary':
            _logger("unknown action: %s", action)
            return

        # TODO(guillermooo): add regexes
        args = {
            'cmd': [sdk.path_to_dart, '--checked', file_name],
            'working_dir': working_dir<commit_msg>Add regexes<commit_after>'''Builds Dart projects intelligently.
'''

import sublime
import sublime_plugin

import os
from functools import partial

from Dart import PluginLogger
from Dart.lib.sdk import SDK
from Dart.lib.dart_project import ViewInspector
from Dart.lib.dart_project import find_pubspec


_logger = PluginLogger(__name__)


class ContextProvider(sublime_plugin.EventListener):
    '''Implements the 'dart_is_project_file' context for .sublime-keymap
    files.
    '''
    def on_query_context(self, view, key, operator, operand, match_all):
        if key == 'dart_is_project_file':
            return ViewInspector(view).is_project_file


class DartBuildProjectCommand(sublime_plugin.WindowCommand):
    '''Orchestrates different build tasks.

    Meant to be called from a key binding.
    '''
    def run(self, action='primary'):
        '''
        @action
          One of: 'primary', 'secondary'
        '''
        view = self.window.active_view()
        if ViewInspector(view).is_pubspec:
            self.window.run_command('dart_build_pubspec', {
                'action': action,
                'file_name': view.file_name()
                })
            return

        self.window.run_command('dart_run', {
            'action': action,
            'file_name': view.file_name()
            })


class AsyncProcessExecutor(object):
    def execute(self, **kwargs):
        self.window.run_command('exec', kwargs)


class DartRunCommand(sublime_plugin.WindowCommand, AsyncProcessExecutor):
    '''Runs a file with the most appropriate action.

    Intended for .dart and .html files.
    '''
    def run(self, file_name, action='primary'):
        '''
        @action
          On of: primary, secondary
        '''
        working_dir = find_pubspec(file_name)
        if not working_dir:
            working_dir = os.path.dirname(file_name)

        sdk = SDK()

        if action == 'primary':
            # TODO(guillermooo): add regexes
            args = {
                    'cmd' : [sdk.path_to_dart2js,
                                '--minify', '-o', file_name + '.js',
                                file_name],
                    'working_dir': working_dir,
                    'file_regex': "(\\S*):(\\d*):(\\d*): (.*)",
                    }
            self.execute(**args)
            return

        if action != 'secondary':
            _logger("unknown action: %s", action)
            return

        args = {
            'cmd': [sdk.path_to_dart, '--checked', file_name],
            'working_dir': working_dir,
            'file_regex': "'file:///(.+)': error: line (\\d+) pos (\\d+): (.*)$"
{'fraction_non_alphanumeric': 0.11344375963020031, 'fraction_numerical': 0.0003852080123266564, 'mean_word_length': 2.052910052910053, 'pattern_counts': {'":': 0, '<': 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': '6968788', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1466, 'n_words': 342}