Skip to content

Commit

Permalink
Refactor notification handler
Browse files Browse the repository at this point in the history
  • Loading branch information
anu-ka committed Apr 29, 2021
1 parent a1142a0 commit 3528b1f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tests/lsp_test_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __enter__(self):
dispatcher = {
PUBLISH_DIAGNOSTICS: self._publish_diagnostics,
WINDOW_SHOW_MESSAGE: self._window_show_message,
WINDOW_LOG_MESSAGE: self._window_log_message,
}
self._endpoint = Endpoint(dispatcher, self._writer.write)
self._thread_pool.submit(self._reader.listen, self._endpoint.consume)
Expand Down Expand Up @@ -223,23 +224,29 @@ def _default_handler(_params):

def _publish_diagnostics(self, publish_diagnostics_params):
"""Internal handler for text document publish diagnostics."""
fut = Future()

def _handler():
callback = self.get_notification_callback(PUBLISH_DIAGNOSTICS)
callback(publish_diagnostics_params)
fut.set_result(None)
return self._handle_notification(
PUBLISH_DIAGNOSTICS, publish_diagnostics_params
)

self._thread_pool.submit(_handler)
return fut
def _window_log_message(self, window_log_message_params):
"""Internal handler for window log message."""
return self._handle_notification(
WINDOW_LOG_MESSAGE, window_log_message_params
)

def _window_show_message(self, window_show_message_params):
"""Internal handler for text document publish diagnostics."""
"""Internal handler for window show message."""
return self._handle_notification(
WINDOW_SHOW_MESSAGE, window_show_message_params
)

def _handle_notification(self, notification_name, params):
"""Internal handler for notifications."""
fut = Future()

def _handler():
callback = self.get_notification_callback(WINDOW_SHOW_MESSAGE)
callback(window_show_message_params)
callback = self.get_notification_callback(notification_name)
callback(params)
fut.set_result(None)

self._thread_pool.submit(_handler)
Expand Down

0 comments on commit 3528b1f

Please sign in to comment.