Skip to content

Commit

Permalink
lsp: Wait for clients to finish creating
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Sep 10, 2023
1 parent 7cde249 commit ec28781
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/esbonio/esbonio/server/features/sphinx_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(self, client_factory: SphinxClientFactory, *args, **kwargs):
self._pending_builds: Dict[str, asyncio.Task] = {}
"""Holds tasks that will trigger a build after a given delay if not cancelled."""

self._client_creating: Optional[asyncio.Task] = None
"""If set, indicates we're in the process of setting up a new client."""

def add_listener(self, event: str, handler):
self.handlers.setdefault(event, set()).add(handler)

Expand Down Expand Up @@ -117,6 +120,10 @@ async def trigger_build(self, uri: Uri):
async def get_client(self, uri: Uri) -> Optional[SphinxClient]:
"""Given a uri, return the relevant sphinx client instance for it."""

# Wait until the new client is created - it might be the one we're looking for!
if self._client_creating:
await self._client_creating

# Always check the fully resolved uri.
resolved_uri = uri.resolve()

Expand All @@ -137,6 +144,12 @@ async def get_client(self, uri: Uri) -> Optional[SphinxClient]:

return None

# Create a new client instance.
self._client_creating = asyncio.create_task(self._create_client(uri))
return await self._client_creating

async def _create_client(self, uri: Uri) -> Optional[SphinxClient]:
"""Create a new sphinx client instance."""
config = await self.server.get_user_config(
"esbonio.sphinx", SphinxConfig, scope=uri
)
Expand Down

0 comments on commit ec28781

Please sign in to comment.