Exemplo n.º 1
0
def get_project_path(window: sublime.Window) -> 'Optional[str]':
    """
    Returns the common root of all open folders in the window
    """
    if len(window.folders()):
        folder_paths = window.folders()
        return folder_paths[0]
    else:
        view = window.active_view()
        if view:
            filename = view.file_name()
            if filename:
                project_path = os.path.dirname(filename)
                debug(
                    "Couldn't determine project directory since no folders are open!",
                    "Using", project_path, "as a fallback.")
                return project_path
            else:
                debug(
                    "Couldn't determine project directory since no folders are open",
                    "and the current file isn't saved on the disk.")
                return None
        else:
            debug("No view is active in current window")
            return None  # https://github.com/tomv564/LSP/issues/219
Exemplo n.º 2
0
 def on_start(cls, window: sublime.Window) -> bool:
     if cls.manages_server():
         server = cls.get_server()
         if server is None or server.get_status() != ServerStatus.READY:
             log_and_show_message('{}: Server not ready'.format(cls.get_displayed_name()))
             return False
     startup_view = window.active_view()
     workspace_folders = [WorkspaceFolder.from_path(folder) for folder in window.folders()]
     message = cls.is_allowed_to_start(window, startup_view, workspace_folders)
     if message:
         log_and_show_message('{}: {}'.format(cls.get_displayed_name(), message))
         return False
     return True
Exemplo n.º 3
0
def get_project_path(window: sublime.Window) -> 'Optional[str]':
    """
    Returns the common root of all open folders in the window
    """
    if len(window.folders()):
        folder_paths = window.folders()
        return folder_paths[0]
    else:
        view = window.active_view()
        if view:
            filename = view.file_name()
            if filename:
                project_path = os.path.dirname(filename)
                debug("Couldn't determine project directory since no folders are open!",
                      "Using", project_path, "as a fallback.")
                return project_path
            else:
                debug("Couldn't determine project directory since no folders are open",
                      "and the current file isn't saved on the disk.")
                return None
        else:
            debug("No view is active in current window")
            return None  # https://github.com/tomv564/LSP/issues/219
Exemplo n.º 4
0
 def __init__(
     self, config: ClientConfig, window: sublime.Window, on_close: Callable[[List[str], str, int], None]
 ) -> None:
     self._on_close = on_close
     self._transport = None  # type: Optional[Transport]
     self._resolved_command = []  # type: List[str]
     self._stderr_lines = []  # type: List[str]
     try:
         variables = extract_variables(window)
         plugin_class = get_plugin(config.name)
         if plugin_class is not None:
             if plugin_class.needs_update_or_installation():
                 plugin_class.install_or_update()
             additional_variables = plugin_class.additional_variables()
             if isinstance(additional_variables, dict):
                 variables.update(additional_variables)
         cwd = window.folders()[0] if window.folders() else None
         transport_config = config.resolve_transport_config(variables)
         self._resolved_command = transport_config.command
         self._transport = create_transport(transport_config, cwd, self)
         sublime.set_timeout_async(self.force_close_transport, self.CLOSE_TIMEOUT_SEC * 1000)
     except Exception as ex:
         self.on_transport_close(-1, ex)