Skip to content

Commit

Permalink
Merge pull request #681 from TheLeoP/fix_assert
Browse files Browse the repository at this point in the history
fix: assert state -> if state:
  • Loading branch information
ms-jpq authored Feb 5, 2025
2 parents 6237214 + d4495f1 commit 9e77f1f
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions coq/lsp/requests/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,28 @@ async def _lsp_notify(stack: Stack, rpayload: _Payload) -> None:
async def cont() -> None:
with _LOCK:
state = _STATE.get(payload.name)
assert state

if payload.uid >= state.uid:
if not state or payload.uid >= state.uid:
encoding = (payload.offset_encoding or "").casefold().replace("-", "")
offset_encoding = _ENCODING_MAP.get(encoding, UTF16)
client = _Client(
name=payload.client,
peers={name for name in payload.client_names if name},
offset_encoding=offset_encoding,
elapsed=timedelta(seconds=monotonic() - state.instance),
elapsed=timedelta(
seconds=monotonic() - state.instance if state else monotonic()
),
message=payload.reply,
)
acc = [
*(state.acc if state and payload.uid == state.uid else ()),
(client, payload.multipart),
]
session = _Session(
uid=payload.uid, instance=state.instance, done=payload.done, acc=acc
uid=payload.uid,
instance=state.instance if state else monotonic(),
done=payload.done,
acc=acc,
)
with _LOCK:
_STATE[payload.name] = session
Expand Down Expand Up @@ -166,35 +170,35 @@ async def async_request(
while True:
with _LOCK:
state = _STATE.get(name)
assert state

if state.uid == uid:
while state.acc:
client, multipart = state.acc.pop()
if multipart:
async for part in _lsp_pull(
multipart, name=name, client=client.name, uid=uid
):
if isinstance(
client.message, MutableMapping
) and isinstance(client.message.get("items"), Sequence):
message = {**client.message, "items": part}
yield replace(client, message=message)
else:
yield replace(client, message=part)
else:
yield client
if state.done:
with _LOCK:
_STATE.pop(name, None)

if state:
if state.uid == uid:
while state.acc:
client, multipart = state.acc.pop()
if multipart:
async for part in _lsp_pull(
multipart, name=name, client=client.name, uid=uid
):
if isinstance(
client.message, MutableMapping
) and isinstance(client.message.get("items"), Sequence):
message = {**client.message, "items": part}
yield replace(client, message=message)
else:
yield replace(client, message=part)
else:
yield client
if state.done:
with _LOCK:
_STATE.pop(name, None)
break
elif state.uid > uid:
break
else:
log.info(
"%s", f"<><> DELAYED LSP RESP <><> :: {name} {state.uid} {uid}"
)
break
elif state.uid > uid:
break
else:
log.info(
"%s", f"<><> DELAYED LSP RESP <><> :: {name} {state.uid} {uid}"
)
break

await activity.wait()

Expand Down

0 comments on commit 9e77f1f

Please sign in to comment.