def on_autofix(self, corrections):
        output_messages = [OutputMessage(
            m['source']['file'],
            hsdev.parse_region(m['region']).to_zero_based(),
            m['level'].capitalize() + ': ' + m['note']['message'].replace('\n', '\n  '),
            m['level']) for m in self.messages]

        self.corrections = corrections
        for corr in self.corrections:
            corr.message_region.to_zero_based()
        self.corrections_dict = dict(((os.path.normpath(c.file), c.message_region.start.line, c.message_region.start.column), c) for c in self.corrections)

        for omsg in output_messages:
            okey = (os.path.normpath(omsg.filename), omsg.region.start.line, omsg.region.start.column)
            if okey in self.corrections_dict:
                omsg.correction = self.corrections_dict[okey]

        set_global_error_messages(output_messages)
        output_text = format_output_messages(output_messages)
        if get_setting_async('show_error_window'):
            sublime.set_timeout(lambda: write_output(
                self.view,
                output_text,
                get_cabal_project_dir_of_file(self.filename) or os.path.dirname(self.filename),
                show_panel = not self.fly_mode and len(output_messages)), 0)
        sublime.set_timeout(lambda: mark_messages_in_views(output_messages), 0)
Beispiel #2
0
    def go_chain(self, cmds):
        try:
            if not cmds:
                self.status_msg.stop()
                output_messages = [
                    OutputMessage(
                        m['source']['file'],
                        OutputPoint(
                            int(m['region']['from']['line']) - 1,
                            int(m['region']['from']['column']) - 1),
                        OutputPoint(
                            int(m['region']['to']['line']) - 1,
                            int(m['region']['to']['column']) - 1),
                        m['level'].capitalize() + ': ' +
                        m['note']['message'].replace('\n', '\n  '), m['level'])
                    for m in self.messages
                ]

                set_global_error_messages(output_messages)
                output_text = format_output_messages(output_messages)
                if output_text:
                    if get_setting_async('show_error_window'):
                        sublime.set_timeout(
                            lambda: write_output(
                                self.view,
                                output_text,
                                get_cabal_project_dir_of_file(self.filename) or
                                os.path.dirname(self.filename),
                                show_panel=not self.fly_mode), 0)
                sublime.set_timeout(
                    lambda: mark_messages_in_views(output_messages), 0)

                # autocomplete.hsdev_client.autofix_show(self.msgs, on_response = self.on_autofix)
            else:
                cmd, tail_cmds = cmds[0], cmds[1:]
                (fn, modify_args, modify_msgs, kwargs) = cmd

                def on_resp(msgs):
                    self.messages.extend(modify_msgs(msgs))
                    self.msgs.extend(msgs)
                    self.go_chain(tail_cmds)

                def on_err(err):
                    self.status_msg.fail()
                    self.go_chain([])

                fn(modify_args(self.filename),
                   contents=self.contents,
                   wait=False,
                   on_response=on_resp,
                   on_error=on_err,
                   **kwargs)
        except Exception as e:
            log('hsdev ghc-mod chain fails with: {0}'.format(e), log_error)
            self.status_msg.stop()
Beispiel #3
0
def wait_ghcmod_and_parse(view, filename, msg, cmds_with_args, alter_messages_cb):
    sublime.set_timeout(lambda: hide_output(view), 0)

    parsed_messages = []

    file_dir = os.path.dirname(filename)

    all_cmds_successful = True
    all_cmds_outputs = []

    for (cmd, args) in cmds_with_args:
        stdout = call_ghcmod_and_wait(args, filename)

        # stdout contains NULL as line endings within one message
        # error_output_regex using indents to determine one message scope
        # Replace NULLs to indents
        out1 = stdout.replace('\0', '\n  ')
        
        # Hlint outputs Error instead Warning for tips
        # so lets replace them
        out = out1.replace('Error', 'Warning')

        success = len(out.strip()) == 0

        if not success:
            all_cmds_outputs.append(out)
            log(u"ghc-mod %s didn't exit with success on '%s'" % (u' '.join(cmd), filename))

        all_cmds_successful &= success

        parsed = parse_output_messages(file_dir, out)
        for p in parsed:
            parsed_messages.append((cmd, p))

    if alter_messages_cb:
        alter_messages_cb(parsed_messages)

    concated_messages = [m[1] for m in parsed_messages]

    # Set global error list
    set_global_error_messages(concated_messages)

    sublime.set_timeout(lambda: mark_messages_in_views(concated_messages), 0)

    output_text = (format_output_messages(concated_messages) if parsed_messages
                   else '\n'.join(all_cmds_outputs))

    exit_code = 0 if all_cmds_successful else 1

    show_output_result_text(view, msg, output_text, exit_code, file_dir)
Beispiel #4
0
    def run(self):
        window, view, file_shown_in_view = get_haskell_command_window_view_file_project()
        if not file_shown_in_view:
            return

        file_dir, file_name = os.path.split(file_shown_in_view)
        log('hdevtools checking ' + file_shown_in_view)
        parsed_output = hdevtools_check(file_shown_in_view)
        if parsed_output is None:
            raise ValueError, "hdevtools failed!"
        log(parsed_output)
        set_global_error_messages(parsed_output)
        sublime.set_timeout(lambda: mark_messages_in_views(parsed_output), 0)
        output_text = "\n".join([p.message for p in parsed_output])
        exit_code = 1 if parsed_output else 0
        show_output_result_text(view, '', output_text, exit_code, file_dir)
Beispiel #5
0
def wait_ghcmod_and_parse(view, filename, msg, cmds_with_args, alter_messages_cb):
    sublime.set_timeout(lambda: hide_output(view), 0)

    parsed_messages = []

    file_dir = os.path.dirname(filename)

    all_cmds_successful = True
    all_cmds_outputs = []

    for (cmd, args) in cmds_with_args:
        stdout = call_ghcmod_and_wait(args, filename)

        # stdout contains NULL as line endings within one message
        # error_output_regex using indents to determine one message scope
        # Replace NULLs to indents
        out = stdout.replace('\0', '\n  ')

        success = len(out.strip()) == 0

        if not success:
            all_cmds_outputs.append(out)
            log(u"ghc-mod %s didn't exit with success on '%s'" % (u' '.join(cmd), filename), log_error)

        all_cmds_successful &= success

        parsed = parse_output_messages(view, file_dir, out)
        for p in parsed:
            parsed_messages.append((cmd, p))

    if alter_messages_cb:
        alter_messages_cb(parsed_messages)

    concated_messages = [m[1] for m in parsed_messages]

    # Set global error list
    set_global_error_messages(concated_messages)

    sublime.set_timeout(lambda: mark_messages_in_views(concated_messages), 0)

    output_text = (format_output_messages(concated_messages) if parsed_messages
                   else '\n'.join(all_cmds_outputs))

    exit_code = 0 if all_cmds_successful else 1

    show_output_result_text(view, msg, output_text, exit_code, file_dir)
Beispiel #6
0
    def go_chain(self, cmds):
        try:
            if not cmds:
                self.status_msg.stop()
                output_messages = [OutputMessage(
                    m['source']['file'],
                    OutputPoint(
                        int(m['region']['from']['line']) - 1,
                        int(m['region']['from']['column']) - 1),
                    OutputPoint(
                        int(m['region']['to']['line']) - 1,
                        int(m['region']['to']['column']) - 1),
                    m['level'].capitalize() + ': ' + m['note']['message'].replace('\n', '\n  '),
                    m['level']) for m in self.messages]

                set_global_error_messages(output_messages)
                output_text = format_output_messages(output_messages)
                if output_text:
                    if get_setting_async('show_error_window'):
                        sublime.set_timeout(lambda: write_output(
                            self.view,
                            output_text,
                            get_cabal_project_dir_of_file(self.filename) or os.path.dirname(self.filename),
                            show_panel = not self.fly_mode), 0)
                sublime.set_timeout(lambda: mark_messages_in_views(output_messages), 0)

                # autocomplete.hsdev_client.autofix_show(self.msgs, on_response = self.on_autofix)
            else:
                cmd, tail_cmds = cmds[0], cmds[1:]
                (fn, modify_args, modify_msgs, kwargs) = cmd

                def on_resp(msgs):
                    self.messages.extend(modify_msgs(msgs))
                    self.msgs.extend(msgs)
                    self.go_chain(tail_cmds)

                def on_err(err):
                    self.status_msg.fail()
                    self.go_chain([])

                fn(modify_args(self.filename), contents = self.contents, wait = False, on_response = on_resp, on_error = on_err, **kwargs)
        except Exception as e:
            log('hsdev ghc-mod chain fails with: {0}'.format(e), log_error)
            self.status_msg.stop()