Пример #1
0
 def run(self):
     while True:
         self.event.wait()
         self.event.clear()
         time.sleep(get_setting_async('lint_check_fly_idle', 5))
         view_ = None
         with self.view as v:
             if v:
                 view_ = v[0]
             v[:] = []
         if view_ is None:
             continue
         auto_check_enabled = get_setting_async('enable_auto_check')
         auto_lint_enabled = get_setting_async('enable_auto_lint')
         sublime.set_timeout(
             lambda: view_.window().run_command(
                 'sublime_haskell_scan_contents'), 0)
         if auto_check_enabled and auto_lint_enabled:
             sublime.set_timeout(
                 lambda: view_.window().run_command(
                     'sublime_haskell_check_and_lint', {'fly': True}), 0)
         elif auto_check_enabled:
             sublime.set_timeout(
                 lambda: view_.window().run_command('sublime_haskell_check',
                                                    {'fly': True}), 0)
         elif auto_lint_enabled:
             sublime.set_timeout(
                 lambda: view_.window().run_command('sublime_haskell_lint',
                                                    {'fly': True}), 0)
Пример #2
0
    def run(self):
        while True:
            view_ = None
            mtime_ = None
            delay = get_setting_async('lint_check_fly_idle', 5)

            with self.view as v:
                view_ = v['view']
                mtime_ = v['mtime']

            if not view_:  # Wait for signal
                self.event.wait()
                self.event.clear()
                time.sleep(delay)
                continue
            
            if time.time() - mtime_ < delay:  # Was modified recently, sleep more
                time.sleep(delay)
                continue
            else:
                with self.view as v:
                    v['view'] = None
                    v['mtime'] = None

                fly_view = view_

                auto_check_enabled = get_setting_async('enable_auto_check')
                auto_lint_enabled = get_setting_async('enable_auto_lint')
                sublime.set_timeout(lambda: fly_view.window().run_command('sublime_haskell_scan_contents'), 0)
                if auto_check_enabled and auto_lint_enabled:
                    sublime.set_timeout(lambda: fly_view.window().run_command('sublime_haskell_check_and_lint', {'fly': True}), 0)
                elif auto_check_enabled:
                    sublime.set_timeout(lambda: fly_view.window().run_command('sublime_haskell_check', {'fly': True}), 0)
                elif auto_lint_enabled:
                    sublime.set_timeout(lambda: fly_view.window().run_command('sublime_haskell_lint', {'fly': True}), 0)
Пример #3
0
def get_type(view, filename, module_name, line, column, cabal=None):
    result = None

    if get_setting_async('enable_hsdev'):
        # Convert from hsdev one-based locations to sublime zero-based positions
        ts = get_types(filename, cabal=cabal)
        pt = FilePosition(line, column).point(view)
        return sorted_types(view, ts, pt)
    column = sublime_column_to_ghc_column(view, line, column)
    line = line + 1
    if get_setting_async('enable_hdevtools'):
        result = hdevtools_type(filename, line, column, cabal=cabal)
    if not result and module_name and get_setting_async('enable_ghc_mod'):
        result = ghcmod_type(filename, module_name, line, column)
    return parse_type_output(view, result) if result else None
Пример #4
0
def get_type(view, filename, module_name, line, column, cabal = None):
    result = None

    if get_setting_async('enable_hsdev'):
        # Convert from hsdev one-based locations to sublime zero-based positions
        ts = get_types(filename, cabal = cabal)
        pt = FilePosition(line, column).point(view)
        return sorted_types(view, ts, pt)
    column = sublime_column_to_ghc_column(view, line, column)
    line = line + 1
    if get_setting_async('enable_hdevtools'):
        result = hdevtools_type(filename, line, column, cabal = cabal)
    if not result and module_name and get_setting_async('enable_ghc_mod'):
        result = ghcmod_type(filename, module_name, line, column)
    return parse_type_output(view, result) if result else None
Пример #5
0
def get_types(filename, on_result=None, cabal=None):
    if get_setting_async('enable_hsdev'):

        def to_file_pos(r):
            return FilePosition(int(r['line']) - 1, int(r['column']) - 1)

        def to_region_type(r):
            return RegionType(r['note']['type'],
                              to_file_pos(r['region']['from']),
                              to_file_pos(r['region']['to']))

        def on_resp(rs):
            ts = [to_region_type(r) for r in rs]
            file_types.set(filename, ts, False)
            on_result(ts)

        if file_types.has(filename):
            return file_types.get(filename)

        wait = on_result is None
        res = hsdev.client.types(
            files=[filename],
            ghc=get_ghc_opts(filename),
            wait=wait,
            on_response=on_resp if on_result is not None else None)
        if res is not None and wait:
            ts = [to_region_type(r) for r in res]
            file_types.set(filename, ts, False)
            return ts
Пример #6
0
def get_types(filename, on_result = None, cabal = None):
    if get_setting_async('enable_hsdev'):
        def to_file_pos(r):
            return FilePosition(int(r['line']) - 1, int(r['column']) - 1)

        def to_region_type(r):
            return RegionType(
                r['note']['type'],
                to_file_pos(r['region']['from']),
                to_file_pos(r['region']['to']))

        def on_resp(rs):
            ts = [to_region_type(r) for r in rs]
            file_types.set(filename, ts, False)
            on_result(ts)

        if file_types.has(filename):
            return file_types.get(filename)

        wait = on_result is None
        res = hsdev.client.types(files = [filename], ghc = get_ghc_opts(filename), wait = wait, on_response = on_resp if on_result is not None else None)
        if res is not None and wait:
            ts = [to_region_type(r) for r in res]
            file_types.set(filename, ts, False)
            return ts
Пример #7
0
def get_type(view, filename, module_name, line, column, cabal = None):
    result = None

    if get_setting_async('enable_hsdev'):
        # Convert from hsdev one-based locations to sublime zero-based positions
        ts = get_types(filename, cabal = cabal)
        pt = FilePosition(line, column).point(view)
        types = sorted(
            list(filter(lambda t: t.region(view).contains(pt), ts)),
            key = lambda t: t.region(view).size())
        return types
    column = sublime_column_to_ghc_column(view, line, column)
    line = line + 1
    if get_setting_async('enable_hdevtools'):
        result = hdevtools_type(filename, line, column, cabal = cabal)
    if not result and module_name and get_setting_async('enable_ghc_mod'):
        result = ghcmod_type(filename, module_name, line, column)
    return parse_type_output(view, result) if result else None
Пример #8
0
def haskell_type(filename, module_name, line, column, cabal = None):
    result = None

    if get_setting_async('enable_hdevtools'):
        result = hdevtools_type(filename, line, column, cabal = cabal)
    if not result:
        if module_name:
            result = ghcmod_type(filename, module_name, line, column, cabal = cabal)
    return parse_type_output(result) if result else None
Пример #9
0
    def on_load(self, view):
        if get_setting_async('use_improved_syntax', True):
            filename = view.file_name()
            if not filename:  # buffer has never been saved
                return

            name = os.path.basename(filename.lower())
            if name.endswith(".hs") or name.endswith(".hsc"):
                set_our_syntax(view, filename)
Пример #10
0
def symbol_info(filename, module_name, symbol_name, cabal=None):
    result = None
    if common.get_setting_async("enable_hdevtools"):
        result = hdevtools.hdevtools_info(filename, symbol_name, cabal=cabal)
    if not result:
        result = ghcmod.ghcmod_info(filename, module_name, symbol_name, cabal=cabal)
    if not result and filename:
        result = ghci.ghci_info(module_name, symbol_name, cabal=cabal)
    return result
Пример #11
0
 def run(self):
     while True:
         self.event.wait()
         self.event.clear()
         time.sleep(get_setting_async('lint_check_fly_idle', 5))
         view_ = None
         with self.view as v:
             if v:
                 view_ = v[0]
             v[:] = []
         if view_ is None:
             continue
         auto_check_enabled = get_setting_async('enable_auto_check')
         auto_lint_enabled = get_setting_async('enable_auto_lint')
         sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_scan_contents'), 0)
         if auto_check_enabled and auto_lint_enabled:
             sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_check_and_lint', {'fly': True}), 0)
         elif auto_check_enabled:
             sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_check', {'fly': True}), 0)
         elif auto_lint_enabled:
             sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_lint', {'fly': True}), 0)
Пример #12
0
def show_output_result_text(view, msg, text, exit_code, base_dir):
    """Shows text (formatted messages) in output with build result"""

    success = exit_code == 0

    success_message = 'SUCCEEDED' if success else 'FAILED'
    output = u'{0}\n\nBuild {1}'.format(text, success_message)

    show_status_message_process(msg, success)
    if not success:
        if get_setting_async('show_output_window'):
            sublime.set_timeout(lambda: write_output(view, output, base_dir), 0)
Пример #13
0
def show_output_result_text(view, msg, text, exit_code, base_dir):
    """Shows text (formatted messages) in output with build result"""

    success = exit_code == 0

    success_message = 'SUCCEEDED' if success else 'FAILED'
    output = u'Build {0}\n\n{1}'.format(success_message, text.strip())

    show_status_message_process(msg, success)
    # Show panel if there is any text to show (without the part that we add)
    if text:
        if get_setting_async('show_output_window'):
            sublime.set_timeout(lambda: write_output(view, output, base_dir), 0)
Пример #14
0
def show_output_result_text(view, msg, text, exit_code, base_dir):
    """Shows text (formatted messages) in output with build result"""

    success = exit_code == 0

    success_message = 'SUCCEEDED' if success else 'FAILED'
    output = u'Build {0}\n\n{1}'.format(success_message, text.strip())

    show_status_message_process(msg, success)
    # Show panel if there is any text to show (without the part that we add)
    if text:
        if get_setting_async('show_output_window'):
            sublime.set_timeout(lambda: write_output(view, output, base_dir),
                                0)
Пример #15
0
def refine_type(decl, hdevtools_only=True):
    """
    Refine type for sources decl
    """
    hdevtools_enabled = common.get_setting_async("enable_hdevtools")

    if decl.location:
        if decl.what == "function" and not decl.type:
            info = None
            if hdevtools_only and hdevtools_enabled:
                info = hdevtools.hdevtools_info(decl.location.filename, decl.name)
            else:
                info = symbol_info(decl.location.filename, decl.module.name, decl.name)
            if info:
                decl.type = info.type
Пример #16
0
def run_build(view, project_name, project_dir, command, use_cabal_dev=None):
    global projects_being_built

    # Don't build if a build is already running for this project
    # We compare the project_name for simplicity (projects with same
    # names are of course possible, but unlikely, so we let them wait)
    if project_name in projects_being_built:
        print "SublimeHaskell: Not building '%s' because it is already being built" % project_name
        sublime.status_message('SublimeHaskell: Already building %s' % project_name)
        return
    # Set project as building
    projects_being_built.add(project_name)

    # Run cabal or cabal-dev
    if use_cabal_dev is None:
        use_cabal_dev = get_setting_async('use_cabal_dev')

    tool = cabal_tool[use_cabal_dev]
    config = cabal_command[command]

    # Title of tool: Cabal, Cabal-Dev
    tool_title = tool['message']
    # Title of action: Cleaning, Building, etc.
    action_title = config['message']
    # Extra arguments lambda
    extra_args = tool['extra']
    # Tool name: cabal, cabal-dev
    tool_name = tool['command']
    # Tool arguments (commands): build, clean, etc.
    tool_steps = config['steps']

    # Assemble command lines to run (possibly multiple steps)
    commands = [extra_args([tool_name] + step) for step in tool_steps]

    log('running build commands: {0}'.format(commands))

    def done_callback():
        # Set project as done being built so that it can be built again
        projects_being_built.remove(project_name)

    # Run them
    run_chain_build_thread(
        view,
        project_dir,
        tool_title + ': ' + action_title + ' ' + project_name,
        commands,
        on_done=done_callback)
Пример #17
0
def run_build(command, use_cabal_dev = None):
    # Run cabal or cabal-dev
    if use_cabal_dev == None:
        use_cabal_dev = get_setting_async('use_cabal_dev')

    tool = cabal_tool[use_cabal_dev]
    config = cabal_command[command]

    # Title of tool: Cabal, Cabal-Dev
    tool_title = tool['message']
    # Title of action: Cleaning, Building, etc.
    action_title = config['message']
    # Extra arguments lambda
    extra_args = tool['extra']
    # Tool name: cabal, cabal-dev
    tool_name = tool['command']
    # Tool arguments (commands): build, clean, etc.
    tool_args = config['args']

    run_build_commands_with(
        lambda name: tool_title + ': ' + action_title + ' ' + name,
        [extra_args([tool_name, arg]) for arg in tool_args])
Пример #18
0
def ghcmod_enabled():
    return get_setting_async('enable_ghc_mod') == True
Пример #19
0
def ghcmod_enabled():
    return get_setting_async('enable_ghc_mod') == True