Skip to content

Commit

Permalink
chore: delete pyodide specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Nov 3, 2024
1 parent 1572399 commit 7332a0b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 108 deletions.
25 changes: 0 additions & 25 deletions pygls/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 3 additions & 30 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"):
Expand All @@ -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"""
Expand Down
54 changes: 1 addition & 53 deletions tests/ls_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and #
# limitations under the License. #
############################################################################
import json
import os
import threading

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7332a0b

Please sign in to comment.