Skip to content

Commit

Permalink
Rename ServerStatus -> ConnectionStatus
Browse files Browse the repository at this point in the history
Summary:
The ServerStatus name isn't great, because
- We now mostly call the "server" the "daemon" instead, given
  that the "server" in LSP refers to our "client" and we want to
  avoid confusion.
- I want to use the name DaemonStatus for a dataclass that can
  include both timing information and the enum value; the enum really
  just describes the current state of the socket connection so I
  think calling it ConnectionStatus is a good way of making sure
  there's a good name available for the dataclass I want to add
  in the next diff.

Reviewed By: grievejia

Differential Revision: D43244193

fbshipit-source-id: 670eecfd0e69e6756dda7bd717e52a4debfd5c8f
  • Loading branch information
stroxler authored and facebook-github-bot committed Feb 13, 2023
1 parent 38b1544 commit 564e2bb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
10 changes: 6 additions & 4 deletions client/commands/code_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ async def handle_status_update_event(
if not self.get_type_errors_availability().is_disabled():
await self.client_type_error_handler.clear_type_errors_for_client()
if status_update_subscription.kind == "Stop":
self.server_state.status_tracker.set_status(state.ServerStatus.DISCONNECTED)
self.server_state.status_tracker.set_status(
state.ConnectionStatus.DISCONNECTED
)
self.client_status_message_handler.log(
"The Pyre code-navigation server has stopped.",
short_message="Pyre code-nav (stopped)",
Expand All @@ -107,7 +109,7 @@ async def handle_status_update_event(
)
elif status_update_subscription.kind == "BusyBuilding":
self.server_state.status_tracker.set_status(
state.ServerStatus.BUCK_BUILDING
state.ConnectionStatus.BUCK_BUILDING
)
self.client_status_message_handler.log(
"The Pyre code-navigation server is busy re-building the project...",
Expand All @@ -116,15 +118,15 @@ async def handle_status_update_event(
)
elif status_update_subscription.kind == "BusyChecking":
self.server_state.status_tracker.set_status(
state.ServerStatus.INCREMENTAL_CHECK
state.ConnectionStatus.INCREMENTAL_CHECK
)
self.client_status_message_handler.log(
"The Pyre code-navigation server is busy re-type-checking the project...",
short_message="Pyre code-nav (checking)",
level=lsp.MessageType.WARNING,
)
elif status_update_subscription.kind == "Idle":
self.server_state.status_tracker.set_status(state.ServerStatus.READY)
self.server_state.status_tracker.set_status(state.ConnectionStatus.READY)
self.client_status_message_handler.log(
READY_MESSAGE,
short_message=READY_SHORT,
Expand Down
16 changes: 11 additions & 5 deletions client/commands/launch_and_subscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def connect_and_subscribe(
**self._auxiliary_logging_info(server_options),
},
)
self.server_state.status_tracker.set_status(state.ServerStatus.READY)
self.server_state.status_tracker.set_status(state.ConnectionStatus.READY)
await self.subscribe(input_channel, output_channel)

async def launch_and_subscribe(
Expand Down Expand Up @@ -286,7 +286,7 @@ async def launch_and_subscribe(
level=lsp.MessageType.WARNING,
fallback_to_notification=True,
)
self.server_state.status_tracker.set_status(state.ServerStatus.STARTING)
self.server_state.status_tracker.set_status(state.ConnectionStatus.STARTING)
start_status = await async_start_pyre_server(
server_options.binary,
start_arguments,
Expand Down Expand Up @@ -389,14 +389,20 @@ async def run(self) -> None:
await self.launch_and_subscribe(server_options)
except asyncio.CancelledError:
error_message = "Explicit termination request"
self.server_state.status_tracker.set_status(state.ServerStatus.DISCONNECTED)
self.server_state.status_tracker.set_status(
state.ConnectionStatus.DISCONNECTED
)
raise
except PyreDaemonShutdown as error:
error_message = f"Pyre server shutdown: {error}"
self.server_state.status_tracker.set_status(state.ServerStatus.DISCONNECTED)
self.server_state.status_tracker.set_status(
state.ConnectionStatus.DISCONNECTED
)
except BaseException:
error_message = traceback.format_exc()
self.server_state.status_tracker.set_status(state.ServerStatus.DISCONNECTED)
self.server_state.status_tracker.set_status(
state.ConnectionStatus.DISCONNECTED
)
raise
finally:
if error_message is not None:
Expand Down
8 changes: 4 additions & 4 deletions client/commands/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async def handle_type_error_event(
self.client_type_error_handler.update_type_errors(
type_error_subscription.errors
)
self.server_state.status_tracker.set_status(state.ServerStatus.READY)
self.server_state.status_tracker.set_status(state.ConnectionStatus.READY)
await self.client_type_error_handler.show_type_errors_to_client()
await self.client_status_message_handler.log_and_show_status_message_to_client(
READY_MESSAGE,
Expand All @@ -355,7 +355,7 @@ async def handle_status_update_event(
await self.client_type_error_handler.clear_type_errors_for_client()
if status_update_subscription.kind == "Rebuilding":
self.server_state.status_tracker.set_status(
state.ServerStatus.BUCK_BUILDING
state.ConnectionStatus.BUCK_BUILDING
)
await self.client_status_message_handler.log_and_show_status_message_to_client(
"Pyre is busy rebuilding the project for type checking...",
Expand All @@ -364,15 +364,15 @@ async def handle_status_update_event(
)
elif status_update_subscription.kind == "Rechecking":
self.server_state.status_tracker.set_status(
state.ServerStatus.INCREMENTAL_CHECK
state.ConnectionStatus.INCREMENTAL_CHECK
)
await self.client_status_message_handler.log_and_show_status_message_to_client(
"Pyre is busy re-type-checking the project...",
short_message="Pyre (checking)",
level=lsp.MessageType.WARNING,
)
elif status_update_subscription.kind == "Ready":
self.server_state.status_tracker.set_status(state.ServerStatus.READY)
self.server_state.status_tracker.set_status(state.ConnectionStatus.READY)
await self.client_status_message_handler.log_and_show_status_message_to_client(
READY_MESSAGE,
short_message=READY_SHORT,
Expand Down
10 changes: 5 additions & 5 deletions client/commands/server_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from . import pyre_server_options


class ServerStatus(enum.Enum):
class ConnectionStatus(enum.Enum):
READY = "READY"
DISCONNECTED = "DISCONNECTED"
NOT_CONNECTED = "NOT_CONNECTED"
Expand All @@ -42,17 +42,17 @@ class OpenedDocumentState:

@dataclasses.dataclass
class DaemonStatusTracker:
_status: ServerStatus = ServerStatus.NOT_CONNECTED
_status: ConnectionStatus = ConnectionStatus.NOT_CONNECTED
_not_ready_timer: Optional[timer.Timer] = None

def set_status(self, new_status: ServerStatus) -> None:
if new_status == ServerStatus.READY:
def set_status(self, new_status: ConnectionStatus) -> None:
if new_status == ConnectionStatus.READY:
self._not_ready_timer = None
elif self._not_ready_timer is None:
self._not_ready_timer = timer.Timer()
self._status = new_status

def get_status(self) -> ServerStatus:
def get_status(self) -> ConnectionStatus:
return self._status

def milliseconds_not_ready(self) -> int:
Expand Down

0 comments on commit 564e2bb

Please sign in to comment.