Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions bundled/tool/lsp_jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Light-weight JSON-RPC over standard IO."""

import atexit
import contextlib
import io
import json
import pathlib
Expand Down Expand Up @@ -98,14 +99,10 @@ def __init__(self, reader: io.TextIOWrapper, writer: io.TextIOWrapper):

def close(self):
"""Closes the underlying streams."""
try:
with contextlib.suppress(Exception):
self._reader.close()
except: # noqa: E722
pass
try:
with contextlib.suppress(Exception):
self._writer.close()
except: # noqa: E722
pass

def send_data(self, data):
"""Send given data in JSON-RPC format."""
Expand Down Expand Up @@ -134,10 +131,8 @@ def __init__(self):
def stop_all_processes(self):
"""Send exit command to all processes and shutdown transport."""
for i in self._rpc.values():
try:
with contextlib.suppress(Exception):
i.send_data({"id": str(uuid.uuid4()), "method": "exit"})
except: # noqa: E722
pass
self._thread_pool.shutdown(wait=False)

def start_process(self, workspace: str, args: Sequence[str], cwd: str) -> None:
Expand Down
8 changes: 2 additions & 6 deletions bundled/tool/lsp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _run_module(
str_output = CustomIO("<stdout>", encoding="utf-8")
str_error = CustomIO("<stderr>", encoding="utf-8")

try:
with contextlib.suppress(SystemExit):
with substitute_attr(sys, "argv", argv):
with redirect_io("stdout", str_output):
with redirect_io("stderr", str_error):
Expand All @@ -181,8 +181,6 @@ def _run_module(
runpy.run_module(module, run_name="__main__")
else:
runpy.run_module(module, run_name="__main__")
except SystemExit:
pass

return RunResult(str_output.get_value(), str_error.get_value())

Expand Down Expand Up @@ -248,7 +246,7 @@ def _run_api(
str_output = CustomIO("<stdout>", encoding="utf-8")
str_error = CustomIO("<stderr>", encoding="utf-8")

try:
with contextlib.suppress(SystemExit):
with substitute_attr(sys, "argv", argv):
with redirect_io("stdout", str_output):
with redirect_io("stderr", str_error):
Expand All @@ -260,7 +258,5 @@ def _run_api(
callback(argv, str_output, str_error, str_input)
else:
callback(argv, str_output, str_error)
except SystemExit:
pass

return RunResult(str_output.get_value(), str_error.get_value())
Loading