Exemplo n.º 1
0
def wait_ghcmod_and_parse(view, file_dir, msg, cmds_with_args, alter_messages_cb):
    sublime.set_timeout(lambda: hide_output(view), 0)

    exit_success = True

    parsed_messages = []

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

        # 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  ').decode('utf-8')

        exit_success = exit_success and len(out) == 0

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

    exit_code = 0 if exit_success else 1

    if alter_messages_cb:
        alter_messages_cb(parsed_messages)

    concated_messages = map(lambda m: m[1], parsed_messages)
    output_text = format_output_messages(concated_messages)

    show_output_result_text(view, msg, output_text, exit_code, file_dir)
    sublime.set_timeout(lambda: mark_messages_in_views(concated_messages), 0)
Exemplo n.º 2
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)
Exemplo n.º 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
        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)
Exemplo n.º 4
0
def call_hdevtools_and_wait(arg_list, filename = None, cabal = None):
    """
    Calls hdevtools with the given arguments.
    Shows a sublime error message if hdevtools is not available.
    """
    if not hdevtools_enabled():
        log("call_hdevtools_and_wait: hdevtools disabled")
        return None

    ghc_opts_args = get_ghc_opts_args(filename, cabal = cabal)
    hdevtools_socket = get_setting_async('hdevtools_socket')
    source_dir = get_source_dir(filename)

    if hdevtools_socket:
        arg_list.append('--socket={0}'.format(hdevtools_socket))
    hdevtools_binary, librarydir = hdevtools_binary_and_library_dir()
    if librarydir is not None:
        arg_list.append('-g')
        arg_list.append('-package-db={0}'.format(librarydir))

    log(hdevtools_binary)
    log(arg_list)
    log(ghc_opts_args)
    try:
        log([hdevtools_binary] + arg_list + ghc_opts_args)
        exit_code, out, err = call_and_wait([hdevtools_binary] + arg_list + ghc_opts_args, cwd = source_dir)

        if err:
            raise Exception("hdevtools exited with status %d and stderr: %s" % (exit_code, err))

        return parse_output_messages(source_dir, out)

    # except OSError as e:
    #     if e.errno == errno.ENOENT:
    #         show_hdevtools_error_and_disable()

    #     return None

    except Exception as e:
        log('calling to hdevtools fails with {0}'.format(e))
        return None