Repository: sublimelsp/LSP

Issue:
When a server returns an error response during the initialize request, show an error dialog to the user
Currently, we silently do the shutdown -> exit dance. There is no indication that something went wrong in a fatal way. The text in the dialog should show from which server the error came, and it should show the error message from the server.

See: https://github.com/sublimelsp/LSP-typescript/issues/15



Discussion:

Resolving patch:
diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py
--- a/plugin/core/sessions.py
+++ b/plugin/core/sessions.py
@@ -506,7 +506,7 @@ def __init__(self, manager: Manager, logger: Logger, workspace_folders: List[Wor
         self.exiting = False
         self._registrations = {}  # type: Dict[str, _RegistrationData]
         self._init_callback = None  # type: Optional[InitCallback]
-        self._exit_result = None  # type: Optional[Tuple[int, Optional[Exception]]]
+        self._initialize_error = None  # type: Optional[Tuple[int, Optional[Exception]]]
         self._views_opened = 0
         self._workspace_folders = workspace_folders
         self._session_views = WeakSet()  # type: WeakSet[SessionViewProtocol]
@@ -679,7 +679,7 @@ def _handle_initialize_success(self, result: Any) -> None:
             self._init_callback = None
 
     def _handle_initialize_error(self, result: Any) -> None:
-        self._exit_result = (result.get('code', -1), Exception(result.get('message', 'Error initializing server')))
+        self._initialize_error = (result.get('code', -1), Exception(result.get('message', 'Error initializing server')))
         # Init callback called after transport is closed to avoid pre-mature GC of Session.
         self.end_async()
 
@@ -844,11 +844,6 @@ def _progress_string(self, token: Any, value: Dict[str, Any]) -> str:
 
     # --- shutdown dance -----------------------------------------------------------------------------------------------
 
-    def exit(self) -> None:
-        # exit() is only called when doing an explicit session shutdown. Ignore errors on exit then.
-        self._exit_result = (0, None)
-        super().exit()
-
     def end_async(self) -> None:
         # TODO: Ensure this function is called only from the async thread
         if self.exiting:
@@ -870,9 +865,9 @@ def on_transport_close(self, exit_code: int, exception: Optional[Exception]) ->
         self.state = ClientStates.STOPPING
         super().on_transport_close(exit_code, exception)
         self._response_handlers.clear()
-        if self._exit_result:
+        if self._initialize_error:
             # Override potential exit error with a saved one.
-            exit_code, exception = self._exit_result
+            exit_code, exception = self._initialize_error
 
         def run_async() -> None:
             mgr = self.manager()
diff --git a/plugin/core/windows.py b/plugin/core/windows.py
--- a/plugin/core/windows.py
+++ b/plugin/core/windows.py
@@ -323,13 +323,13 @@ def handle_message_request(self, session: Session, params: Any, request_id: Any)
             MessageRequestHandler(view, session, request_id, params, session.config.name).show()
 
     def restart_sessions_async(self) -> None:
-        self.end_sessions_async()
+        self._end_sessions_async()
         listeners = list(self._listeners)
         self._listeners.clear()
         for listener in listeners:
             self.register_listener_async(listener)
 
-    def end_sessions_async(self) -> None:
+    def _end_sessions_async(self) -> None:
         for session in self._sessions:
             session.end_async()
         self._sessions.clear()


Test patch: