Skip to content

Commit 55cce02

Browse files
committed
Attempt to fix truncated Jedi LSP responses
This patch attempts to fix the truncated Jedit LSP responses which produce warning messages about content-lenght mismatch. It does so by looping around and trying again upon an empty read. The theory is that the content producer is just not ready with more data yet. - add function parameter 'max_empty_parts_in_a_row' with a default value of 50. This will be decremented on each empty read. - change the default value of the 'max_parts' parameter to 100 since we should get larger chunks on each successful read. Either of these values could be adjusted based on experience.
1 parent d8b6705 commit 55cce02

File tree

1 file changed

+4
-3
lines changed
  • python_packages/jupyter_lsp/jupyter_lsp

1 file changed

+4
-3
lines changed

python_packages/jupyter_lsp/jupyter_lsp/stdio.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def read(self) -> None:
9797
self.log.exception("%s couldn't enqueue message: %s", self, message)
9898
await self.sleep()
9999

100-
def _read_content(self, length: int, max_parts=1000) -> Optional[bytes]:
100+
def _read_content(self, length: int, max_parts=100, max_empty_parts_in_a_row=50) -> Optional[bytes]:
101101
"""Read the full length of the message unless exceeding max_parts.
102102
103103
See https://github.com/krassowski/jupyterlab-lsp/issues/450
@@ -116,10 +116,11 @@ def _read_content(self, length: int, max_parts=1000) -> Optional[bytes]:
116116
raw = None
117117
raw_parts: List[bytes] = []
118118
received_size = 0
119-
while received_size < length and len(raw_parts) < max_parts:
119+
while received_size < length and len(raw_parts) < max_parts and max_empty_parts_in_a_row > 0:
120120
part = self.stream.read(length)
121121
if part is None:
122-
break # pragma: no cover
122+
--max_empty_parts_in_a_row
123+
continue # pragma: no cover
123124
received_size += len(part)
124125
raw_parts.append(part)
125126

0 commit comments

Comments
 (0)