コード例 #1
0
def pyls(tmpdir):
    """ Return an initialized python LS """
    ls = PythonLanguageServer(StringIO, StringIO)

    ls.m_initialize(processId=1,
                    rootUri=uris.from_fs_path(str(tmpdir)),
                    initializationOptions={})

    return ls
コード例 #2
0
def pyls():
    """ Return an initialized python LS """
    rfile = StringIO()
    wfile = StringIO()
    ls = PythonLanguageServer(rfile, wfile)

    ls.m_initialize(processId=1,
                    rootPath=os.path.dirname(__file__),
                    initializationOptions={})

    return ls
コード例 #3
0
def pyls(tmpdir):
    """ Return an initialized python LS """
    rfile = StringIO()
    wfile = StringIO()
    ls = PythonLanguageServer(rfile, wfile)

    ls.m_initialize(
        processId=1,
        rootPath=str(tmpdir),
        initializationOptions={}
    )

    return ls
コード例 #4
0
def client_server():
    """ A fixture to setup a client/server """

    # Client to Server pipe
    csr, csw = os.pipe()
    # Server to client pipe
    scr, scw = os.pipe()

    server_thread = Thread(target=start_io_lang_server,
                           args=(os.fdopen(csr, 'rb'), os.fdopen(scw, 'wb'),
                                 PythonLanguageServer))
    server_thread.daemon = True
    server_thread.start()

    client = PythonLanguageServer(os.fdopen(scr, 'rb'), os.fdopen(csw, 'wb'))
    client_thread = Thread(target=start_client, args=[client])
    client_thread.daemon = True
    client_thread.start()

    yield client

    shutdown_response = client._endpoint.request('shutdown').result(
        timeout=CALL_TIMEOUT)
    assert shutdown_response is None
    client._endpoint.notify('exit')
コード例 #5
0
    def __init__(self):
        # Client to Server pipe
        csr, csw = os.pipe()
        # Server to client pipe
        scr, scw = os.pipe()

        self.server_thread = Thread(
            target=start_io_lang_server,
            args=(
                os.fdopen(csr, "rb"),
                os.fdopen(scw, "wb"),
                False,
                hdl_checker.lsp.HdlCheckerLanguageServer,
            ),
        )

        self.server_thread.daemon = True
        self.server_thread.start()

        # Object being tested is the server thread. Avoid both objects
        # competing for the same cache by using the raw Python language server
        self.client = PythonLanguageServer(os.fdopen(scr, "rb"),
                                           os.fdopen(csw, "wb"),
                                           start_io_lang_server)

        self.client_thread = Thread(target=_startClient, args=[self.client])
        self.client_thread.daemon = True
        self.client_thread.start()
コード例 #6
0
    def test_it(self):
        inp = BytesIO()
        outp = BytesIO()
        client = _Client(inp)
        check_parent_process = True
        server = PythonLanguageServer(inp, outp, check_parent_process)

        # init
        params = {
            "processId": os.getpid(),
            "rootUri": f"file://{os.getcwd()}",
            "rootPath": os.getcwd(),
        }
        client.request(client.make_message("initialize", params))
        server.start()
        print(outp.getvalue().decode("utf-8"))

        # completion
        params = {
            "textDocument": {
                "uri": f"file://{os.getcwd()}/something.py",
            },
            "position": {
                "line": 1,
                "character": 7,
            },
        }
        client.request(client.make_message("textDocument/completion", params))
        server.start()
        print(outp.getvalue().decode("utf-8"))

        # shutdown
        params = {}
        client.request(client.make_message("shutdown", params))
        server.start()
        client.request(client.make_message("exit", params))
        print(outp.getvalue().decode("utf-8"))
        server.start()

        # xxx
        from jedi.evaluate.compiled.subprocess import _subprocesses
        for p in list(_subprocesses.values()):
            p.kill()
コード例 #7
0
class LspWebsocketHandler(WebSocketServerProtocol):
    def onConnect(self, *args, **kwargs):
        self.pyls = None
        self.read_stream = None
        self.write_stream = None

    def onOpen(self):
        self.read_stream = BytesIO()
        self.write_stream = WebsocketPylsWriterAdapter(self)
        self.pyls = PythonLanguageServer(self.read_stream, self.write_stream)

    def onMessage(self, payload, is_binary):
        self.read_stream.truncate(0)
        self.read_stream.write(payload)
        self.read_stream.seek(0)
        self.pyls.start()

    def onClose(self, wasClean, code, reason):
        self.read_stream.close()
        self.write_stream.close()
        self.pyls = None
コード例 #8
0
    def __init__(self, check_parent_process=False):
        # Client to Server pipe
        csr, csw = os.pipe()
        # Server to client pipe
        scr, scw = os.pipe()

        self.server_thread = Thread(target=start_io_lang_server, args=(
            os.fdopen(csr, 'rb'), os.fdopen(scw, 'wb'), check_parent_process, PythonLanguageServer
        ))
        self.server_thread.daemon = True
        self.server_thread.start()

        self.client = PythonLanguageServer(os.fdopen(scr, 'rb'), os.fdopen(csw, 'wb'), start_io_lang_server)
        self.client_thread = Thread(target=start_client, args=[self.client])
        self.client_thread.daemon = True
        self.client_thread.start()
コード例 #9
0
    def __init__(self, check_parent_process=False):
        # Client to Server pipe
        csr, csw = os.pipe()
        # Server to client pipe
        scr, scw = os.pipe()

        ParallelKind = multiprocessing.Process if os.name != 'nt' else Thread

        self.process = ParallelKind(target=start_io_lang_server,
                                    args=(os.fdopen(csr, 'rb'),
                                          os.fdopen(scw, 'wb'),
                                          check_parent_process,
                                          PythonLanguageServer))
        self.process.start()

        self.client = PythonLanguageServer(os.fdopen(scr, 'rb'),
                                           os.fdopen(csw, 'wb'),
                                           start_io_lang_server)
        self.client_thread = Thread(target=start_client, args=[self.client])
        self.client_thread.daemon = True
        self.client_thread.start()
コード例 #10
0
    def __init__(self, check_parent_process=False):
        # Client to Server pipe
        csr, csw = os.pipe()
        # Server to client pipe
        scr, scw = os.pipe()

        if os.name == 'nt':
            ParallelKind = Thread
        else:
            if sys.version_info[:2] >= (3, 8):
                ParallelKind = multiprocessing.get_context("fork").Process  # pylint: disable=no-member
            else:
                ParallelKind = multiprocessing.Process

        self.process = ParallelKind(target=start_io_lang_server, args=(
            os.fdopen(csr, 'rb'), os.fdopen(scw, 'wb'), check_parent_process, PythonLanguageServer
        ))
        self.process.start()

        self.client = PythonLanguageServer(os.fdopen(scr, 'rb'), os.fdopen(csw, 'wb'), start_io_lang_server)
        self.client_thread = Thread(target=start_client, args=[self.client])
        self.client_thread.daemon = True
        self.client_thread.start()
コード例 #11
0
 def onOpen(self):
     self.read_stream = BytesIO()
     self.write_stream = WebsocketPylsWriterAdapter(self)
     self.pyls = PythonLanguageServer(self.read_stream, self.write_stream)
コード例 #12
0

def request(message, o=o):
    o.seek(0)
    body = json.dumps(message).encode("utf-8")
    lines = [f"Content-Length: {len(body)}".encode("utf-8"), b"\r\n", b"\r\n", body]
    for line in lines:
        o.write(line)
    o.seek(0)


import logging
logging.basicConfig(level=logging.DEBUG)
# logging.basicConfig(level=logging.INFO)
check_parent_process = False
server = PythonLanguageServer(o, sys.stdout.buffer, check_parent_process)


# t = threading.Thread(target=server.start, daemon=True)
# t.start()

import os
message = {
    "jsonrpc": "2.0",
    "method": "initialize",
    "params": {
        "processId": os.getpid(),
        "rootUri": f"file://{os.getcwd()}",
        "rootPath": os.getcwd(),
    },
    "id": 1,