<commit_before>import sublime
import sublime_plugin

from .lint import persist
from .lint import quick_fix
from .lint import util


MYPY = False
if MYPY:
    from typing import Callable, List

    LintError = persist.LintError


class SublimeLinterQuickActions(sublime_plugin.TextCommand):
    def is_visible(self, quiet=False):
        # type: (bool) -> bool
        return len(self.view.sel()) == 1

    def run(self, edit, quiet=False):
        # type: (sublime.Edit, bool) -> None
        view = self.view
        window = view.window()
        assert window

        if len(self.view.sel()) != 1:
            window.status_message("Not implemented for multiple selections")
            return

        sel = view.sel()[0]
        filename = util.get_filename(view)
        if sel.empty():
            char_selection = sublime.Region(sel.a, sel.a + 1)
            errors = get_errors_where(
                filename,
                lambda region: region.intersects(char_selection)
            )
            if not errors:
                sel = view.full_line(sel.a)
                errors = get_errors_where(
                    filename,
                    lambda region: region.intersects(sel)
                )
        else:
            errors = get_errors_where(
                filename,
                lambda region: region.intersects(sel)
            )

        def on_done(idx):
            # type: (int) -> None
            if idx < 0:
                return

            action = actions[idx]
            quick_fix.apply_fix(action.fn, view)

        actions = sorted(
            list(quick_fix.actions_for_errors(errors, view)),
            key=lambda action: (-len(action.solves), action.description)
        )
        if not actions:
            if quiet:
                window.show_quick_panel(
                    ["No actions available."],
                    lambda x: None
                )
            else:
                window.status_message("No actions available")
        elif len(actions) == 1:
            on_done(0)
        else:
            window.show_quick_panel(
                [action.description for action in actions],
                on_done
            )


def get_errors_where(filename, fn):
    # type: (str, Callable[[sublime.Region], bool]) -> List[LintError]
    return [
        error for error in persist.file_errors[filename]
        if fn(error['region'])
    ]<commit_msg>update messaging for consistency<commit_after>import sublime
import sublime_plugin

from .lint import persist
from .lint import quick_fix
from .lint import util


MYPY = False
if MYPY:
    from typing import Callable, List

    LintError = persist.LintError


class SublimeLinterQuickActions(sublime_plugin.TextCommand):
    def is_visible(self, quiet=False):
        # type: (bool) -> bool
        return len(self.view.sel()) == 1

    def run(self, edit, quiet=False):
        # type: (sublime.Edit, bool) -> None
        view = self.view
        window = view.window()
        assert window

        if len(self.view.sel()) != 1:
            window.status_message("Quick actions don't support multiple selections")
            return

        sel = view.sel()[0]
        filename = util.get_filename(view)
        if sel.empty():
            char_selection = sublime.Region(sel.a, sel.a + 1)
            errors = get_errors_where(
                filename,
                lambda region: region.intersects(char_selection)
            )
            if not errors:
                sel = view.full_line(sel.a)
                errors = get_errors_where(
                    filename,
                    lambda region: region.intersects(sel)
                )
        else:
            errors = get_errors_where(
                filename,
                lambda region: region.intersects(sel)
            )

        def on_done(idx):
            # type: (int) -> None
            if idx < 0:
                return

            action = actions[idx]
            quick_fix.apply_fix(action.fn, view)

        actions = sorted(
            list(quick_fix.actions_for_errors(errors, view)),
            key=lambda action: (-len(action.solves), action.description)
        )
        if not actions:
            if quiet:
                window.show_quick_panel(
                    ["No quick action available."],
                    lambda x: None
                )
            else:
                window.status_message("No quick action available")
        elif len(actions) == 1:
            on_done(0)
        else:
            window.show_quick_panel(
                [action.description for action in actions],
                on_done
            )


def get_errors_where(filename, fn):
    # type: (str, Callable[[sublime.Region], bool]) -> List[LintError]
    return [
        error for error in persist.file_errors[filename]
        if fn(error['region'])
    ]
{'fraction_non_alphanumeric': 0.091317671092952, 'fraction_numerical': 0.0028600612870275793, 'mean_word_length': 1.5836411609498682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1951053', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1290, 'n_words': 326}