Example #1
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
Example #2
0
def haskell_type(view, filename, module_name, line, column, cabal=None):
    result = None

    if hsdev.hsdev_enabled():
        # Convert from hsdev one-based locations to sublime zero-based positions
        def to_file_pos(r):
            return FilePosition(int(r['line']) - 1, int(r['column']) - 1)

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

        ts = autocomplete.hsdev_client.ghcmod_type(filename,
                                                   line + 1,
                                                   column + 1,
                                                   ghc=get_ghc_opts(filename))
        if ts:
            return [to_region_type(r) for r in ts]
        return None
    column = sublime_column_to_ghc_column(view, line, column)
    line = line + 1
    if hdevtools_enabled():
        result = hdevtools_type(filename, line, column, cabal=cabal)
    if not result and module_name and ghcmod_enabled():
        result = ghcmod_type(filename, module_name, line, column)
    return parse_type_output(view, result) if result else None
Example #3
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
Example #4
0
def haskell_types(filename, on_result, cabal = None):
    result = None
    if hsdev.hsdev_enabled():
        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):
            on_result([to_region_type(r) for r in rs])
        autocomplete.hsdev_client.types(files = [filename], ghc = get_ghc_opts(filename), wait = False, on_response = on_resp)
Example #5
0
def haskell_types(filename, on_result, cabal=None):
    result = None
    if hsdev.hsdev_enabled():

        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):
            on_result([to_region_type(r) for r in rs])

        autocomplete.hsdev_client.types(files=[filename],
                                        ghc=get_ghc_opts(filename),
                                        wait=False,
                                        on_response=on_resp)
Example #6
0
def haskell_type(view, filename, module_name, line, column, cabal = None):
    result = None

    if hsdev.hsdev_enabled():
        # Convert from hsdev one-based locations to sublime zero-based positions
        def to_file_pos(r):
            return FilePosition(int(r['line']) - 1, int(r['column']) - 1)
        def to_region_type(r):
            return RegionType(
                r['type'],
                to_file_pos(r['region']['from']),
                to_file_pos(r['region']['to']))
        ts = autocomplete.hsdev_client.ghcmod_type(filename, line + 1, column + 1, ghc = get_ghc_opts(filename))
        if ts:
            return [to_region_type(r) for r in ts]
        return None
    column = sublime_column_to_ghc_column(view, line, column)
    line = line + 1
    if hdevtools_enabled():
        result = hdevtools_type(filename, line, column, cabal = cabal)
    if not result and module_name and ghcmod_enabled():
        result = ghcmod_type(filename, module_name, line, column)
    return parse_type_output(view, result) if result else None