def __init__(self, window, settings, backend=None):
        self.window = window

        self.conts = {} # Map from uuid to response handler
        self.is_alive  = True
        self.is_active = False
        self.process   = None
        self.project_path = first_folder(window)
        (project_in, project_name) = os.path.split(self.project_path)
        self.project_name = project_name

        reset_env(settings.add_to_PATH)

        if backend is None:
            self._backend = stack_ide_start(self.project_path, self.project_name, self.handle_response)
        else: # for testing
            self._backend = backend
            self._backend.handler = self.handle_response

        self.is_active = True
        self.include_targets = set()

        # TODO: could check packages here to fix the 'project_dir must equal packagename issue'

        sublime.set_timeout_async(self.load_initial_targets, 0)
Exemple #2
0
    def __init__(self, window, settings, backend=None):
        self.window = window

        self.conts = {}  # Map from uuid to response handler
        self.is_alive = True
        self.is_active = False
        self.process = None
        self.project_path = first_folder(window)
        (project_in, project_name) = os.path.split(self.project_path)
        self.project_name = project_name

        reset_env(settings.add_to_PATH)

        if backend is None:
            self._backend = stack_ide_start(self.project_path,
                                            self.project_name,
                                            self.handle_response)
        else:  # for testing
            self._backend = backend
            self._backend.handler = self.handle_response

        self.is_active = True
        self.include_targets = set()

        # TODO: could check packages here to fix the 'project_dir must equal packagename issue'

        sublime.set_timeout_async(self.load_initial_targets, 0)
    def _handle_response(self,response):

        if len(response) < 1:
            return

        infos = parse_span_info_response(response)
        (props, scope), span = next(infos)
        window = self.view.window()
        if props.defSpan:
            full_path = os.path.join(first_folder(window), props.defSpan.filePath)
            window.open_file(
            '{}:{}:{}'.format(full_path, props.defSpan.fromLine or 0, props.defSpan.fromColumn or 0), sublime.ENCODED_POSITION)
        elif scope.importedFrom:
            sublime.status_message("Cannot navigate to {}, it is imported from {}".format(props.name, scope.importedFrom.module))
        else:
            sublime.status_message("{} not found!", props.name)
def configure_instance(window, settings):

    folder = first_folder(window)

    if not folder:
        msg = "No folder to monitor for window " + str(window.id())
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not has_cabal_file(folder):
        msg = "No cabal file found in " + folder
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not os.path.isfile(expected_cabalfile(folder)):
        msg = "Expected cabal file " + expected_cabalfile(folder) + " not found"
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not is_stack_project(folder):
        msg = "No stack.yaml in path " + folder
        Log.warning("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

        # TODO: We should also support single files, which should get their own StackIDE instance
        # which would then be per-view. Have a registry per-view that we check, then check the window.

    else:
        try:
            # If everything looks OK, launch a StackIDE instance
            Log.normal("Initializing window", window.id())
            instance = StackIDE(window, settings)
        except FileNotFoundError as e:
            instance = NoStackIDE("instance init failed -- stack not found")
            Log.error(e)
            complain('stack-not-found',
                "Could not find program 'stack'!\n\n"
                "Make sure that 'stack' and 'stack-ide' are both installed. "
                "If they are not on the system path, edit the 'add_to_PATH' "
                "setting in SublimeStackIDE  preferences." )
        except Exception:
            instance = NoStackIDE("instance init failed -- unknown error")
            Log.error("Failed to initialize window " + str(window.id()) + ":")
            Log.error(traceback.format_exc())


    return instance
def configure_instance(window, settings):

    folder = first_folder(window)

    if not folder:
        msg = "No folder to monitor for window " + str(window.id())
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not has_cabal_file(folder):
        msg = "No cabal file found in " + folder
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not os.path.isfile(expected_cabalfile(folder)):
        msg = "Expected cabal file " + expected_cabalfile(
            folder) + " not found"
        Log.normal("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

    elif not is_stack_project(folder):
        msg = "No stack.yaml in path " + folder
        Log.warning("Window {}: {}".format(str(window.id()), msg))
        instance = NoStackIDE(msg)

        # TODO: We should also support single files, which should get their own StackIDE instance
        # which would then be per-view. Have a registry per-view that we check, then check the window.

    else:
        try:
            # If everything looks OK, launch a StackIDE instance
            Log.normal("Initializing window", window.id())
            instance = StackIDE(window, settings)
        except FileNotFoundError as e:
            instance = NoStackIDE("instance init failed -- stack not found")
            Log.error(e)
            complain(
                'stack-not-found', "Could not find program 'stack'!\n\n"
                "Make sure that 'stack' and 'stack-ide' are both installed. "
                "If they are not on the system path, edit the 'add_to_PATH' "
                "setting in SublimeStackIDE  preferences.")
        except Exception:
            instance = NoStackIDE("instance init failed -- unknown error")
            Log.error("Failed to initialize window " + str(window.id()) + ":")
            Log.error(traceback.format_exc())

    return instance
Exemple #6
0
    def reset_error_panel(self):
        """
        Creates and configures the error panel for the current window
        """
        panel = self.window.create_output_panel("hide_errors")
        panel.set_read_only(False)

        # This turns on double-clickable error/warning messages in the error panel
        # using a regex that looks for the form file_name:line:column: error_message
        # The error_message could be improved as currently it says KindWarning: or KindError:
        # Perhaps grabbing the next line? Or the whole message?
        panel.settings().set("result_file_regex", "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$")
        panel.settings().set("result_base_dir", first_folder(self.window))

        # Seems to force the panel to refresh after we clear it:
        self.hide_error_panel()

        # Clear the panel. TODO: should be unnecessary? https://www.sublimetext.com/forum/viewtopic.php?f=6&t=2044
        panel.run_command("clear_error_panel")

        # TODO store the panel somewhere so we can reuse it.
        return panel
Exemple #7
0
 def open_view_for_path(self, relative_path):
     full_path = os.path.join(first_folder(self.window), relative_path)
     self.window.open_file(full_path)
Exemple #8
0
 def find_view_for_path(self, relative_path):
     full_path = os.path.join(first_folder(self.window), relative_path)
     return self.window.find_open_file(full_path)
Exemple #9
0
 def open_view_for_path(self, relative_path):
     full_path = os.path.join(first_folder(self.window), relative_path)
     self.window.open_file(full_path)
Exemple #10
0
 def find_view_for_path(self, relative_path):
     full_path = os.path.join(first_folder(self.window), relative_path)
     return self.window.find_open_file(full_path)