From 7332a0bb61d43d5c698effc43418484422d3aaba Mon Sep 17 00:00:00 2001 From: Alex Carney Date: Sun, 27 Oct 2024 19:23:25 +0000 Subject: [PATCH] chore: delete pyodide specific code --- pygls/server.py | 25 ---------------------- tests/conftest.py | 33 +++-------------------------- tests/ls_setup.py | 54 +---------------------------------------------- 3 files changed, 4 insertions(+), 108 deletions(-) diff --git a/pygls/server.py b/pygls/server.py index 12df776c..60ede030 100644 --- a/pygls/server.py +++ b/pygls/server.py @@ -42,23 +42,6 @@ logger = logging.getLogger(__name__) -class PyodideTransportAdapter: - """Protocol adapter which overrides write method. - - Write method sends data to stdout. - """ - - def __init__(self, wfile): - self.wfile = wfile - - def close(self): - self.wfile.close() - - def write(self, data): - self.wfile.write(data) - self.wfile.flush() - - class JsonRPCServer: """Base server class @@ -147,14 +130,6 @@ def start_io( finally: self.shutdown() - def start_pyodide(self): - logger.info("Starting Pyodide server") - - # Note: We don't actually start anything running as the main event - # loop will be handled by the web platform. - transport = PyodideTransportAdapter(sys.stdout) - self.protocol.set_writer(transport) # type: ignore[arg-type] - def start_tcp(self, host: str, port: int) -> None: """Starts TCP server.""" logger.info("Starting TCP server on %s:%s", host, port) diff --git a/tests/conftest.py b/tests/conftest.py index 3cdf2e87..974e31ea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,19 +24,14 @@ from typing import Optional import pytest -from lsprotocol import types, converters +from lsprotocol import converters, types -from pygls import uris, IS_PYODIDE +from pygls import uris from pygls.feature_manager import FeatureManager from pygls.lsp.client import BaseLanguageClient from pygls.workspace import Workspace -from .ls_setup import ( - NativeClientServer, - PyodideClientServer, - setup_ls_features, -) - +from .ls_setup import ClientServer, setup_ls_features DOC = """document for @@ -50,11 +45,6 @@ WORKSPACE_DIR = REPO_DIR / "examples" / "servers" / "workspace" -ClientServer = NativeClientServer -if IS_PYODIDE: - ClientServer = PyodideClientServer - - @pytest.fixture(autouse=False) def client_server(request): if hasattr(request, "param"): @@ -72,23 +62,6 @@ def client_server(request): client_server.stop() -@pytest.fixture() -def event_loop(): - """Redefine `pytest-asyncio's default event_loop fixture to match the scope - of our client fixture.""" - - policy = asyncio.get_event_loop_policy() - - loop = policy.new_event_loop() - yield loop - - try: - # Not implemented on pyodide - loop.close() - except NotImplementedError: - pass - - @pytest.fixture def feature_manager(): """Return a feature manager""" diff --git a/tests/ls_setup.py b/tests/ls_setup.py index b86f3289..43812b76 100644 --- a/tests/ls_setup.py +++ b/tests/ls_setup.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # # limitations under the License. # ############################################################################ -import json import os import threading @@ -51,58 +50,7 @@ def cmd_test2(ls, *args): # pylint: disable=unused-variable return True, threading.get_ident() -class PyodideTestTransportAdapter: - """Transort adapter that's only useful for tests in a pyodide environment.""" - - def __init__(self, dest: LanguageServer): - self.dest = dest - - def close(self): ... - - def write(self, data): - object_hook = self.dest.protocol._deserialize_message - self.dest.protocol._procedure_handler(json.loads(data, object_hook=object_hook)) - - -class PyodideClientServer: - """Implementation of the `client_server` fixture for use in a pyodide - environment.""" - - def __init__(self, LS=LanguageServer): - self.server = LS("pygls-server", "v1") - self.client = LS("pygls-client", "v1") - - self.server.protocol.set_writer(PyodideTestTransportAdapter(self.client)) - self.server.protocol._include_headers = True - - self.client.protocol.set_writer(PyodideTestTransportAdapter(self.server)) - self.client.protocol._include_headers = True - - def start(self): - self.initialize() - - def stop(self): ... - - @classmethod - def decorate(cls): - return pytest.mark.parametrize("client_server", [cls], indirect=True) - - def initialize(self): - response = self.client.protocol.send_request( - INITIALIZE, - InitializeParams( - process_id=12345, root_uri="file://", capabilities=ClientCapabilities() - ), - ).result(timeout=CALL_TIMEOUT) - - assert response.capabilities is not None - - def __iter__(self): - yield self.client - yield self.server - - -class NativeClientServer: +class ClientServer: def __init__(self, LS=LanguageServer): # Client to Server pipe csr, csw = os.pipe()