Coder Social home page Coder Social logo

python-jsonrpc-server's Introduction

Python JSON RPC Server

image

image

image

A Python 2.7 and 3.4+ server implementation of the JSON RPC 2.0 protocol. This library has been pulled out of the Python Language Server project.

Asynchronous request handling is supported using Python 3's concurrent.futures module and the Python 2 concurrent.futures backport.

Installation

pip install -U python-jsonrpc-server

Examples

The examples directory contains two examples of running language servers over websockets. examples/langserver.py shows how to run a language server in-memory. examples/langserver_ext.py shows how to run a subprocess language server, in this case the Python Language Server.

Start by installing tornado and python-language-server

pip install python-language-server[all] tornado

Then running python examples/langserver.py or python examples/langserver_ext.py will host a websocket on ws://localhost:3000/python.

To setup a client, you can use the examples from Monaco Language Client.

Development

To run the test suite:

pip install .[test] && tox

License

This project is made available under the MIT License.

python-jsonrpc-server's People

Contributors

bnavigator avatar dalthviz avatar delta003 avatar gatesn avatar jroitgrund avatar mcepl avatar mpanarin avatar steff456 avatar svc-excavator-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-jsonrpc-server's Issues

Can't launch the server

Hello everyone, could you please help me?
Im trying to run the server via py examples/langserver.py but it doesn't seem to work.
First there was the following error:
Traceback (most recent call last): File "C:/Users/79204/source/Talent Lab/python-jsonrpc-server/examples/langserver_ext.py", line 5, in <module> from tornado import ioloop, process, web, websocket ModuleNotFoundError: No module named 'tornado'

So I ran this command pip install python-language-server[all] tornado and now it gives me the following error:
Traceback (most recent call last): File "examples/langserver.py", line 74, in <module> app.listen(3000, address='127.0.0.1') File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\web.py", line 2116, in listen server.listen(port, address) File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\tcpserver.py", line 152, in listen self.add_sockets(sockets) File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets self._handlers[sock.fileno()] = add_accept_handler( File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler io_loop.add_handler(sock, accept_handler, IOLoop.READ) File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ) File "C:\Users\79204\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader raise NotImplementedError NotImplementedError

I can't get it fixed since I don't know python, but I really need to set up a python language server for monaco editor :)
Looking forward for your help

Tests failing with Python 3.8

[   11s] =================================== FAILURES ===================================
[   11s] ______________________________ test_request_error ______________________________
[   11s] 
[   11s] endpoint = <pyls_jsonrpc.endpoint.Endpoint object at 0x7f8e1ab39ee0>
[   11s] consumer = <MagicMock id='140248310062672'>
[   11s] 
[   11s]     def test_request_error(endpoint, consumer):
[   11s]         future = endpoint.request('methodName', {'key': 'value'})
[   11s]         assert not future.done()
[   11s]     
[   11s]         consumer.assert_called_once_with({
[   11s]             'jsonrpc': '2.0',
[   11s]             'id': MSG_ID,
[   11s]             'method': 'methodName',
[   11s]             'params': {'key': 'value'}
[   11s]         })
[   11s]     
[   11s]         # Send an error back from the client
[   11s]         error = exceptions.JsonRpcInvalidRequest(data=1234)
[   11s] >       endpoint.consume({
[   11s]             'jsonrpc': '2.0',
[   11s]             'id': MSG_ID,
[   11s]             'error': error.to_dict()
[   11s]         })
[   11s] 
[   11s] test/test_endpoint.py:86: 
[   11s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   11s] pyls_jsonrpc/endpoint.py:109: in consume
[   11s]     self._handle_response(message['id'], message.get('result'), message.get('error'))
[   11s] pyls_jsonrpc/endpoint.py:241: in _handle_response
[   11s]     request_future.set_result(result)
[   11s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   11s] 
[   11s] self = <Future at 0x7f8e1ab3fb20 state=finished raised JsonRpcInvalidRequest>
[   11s] result = None
[   11s] 
[   11s]     def set_result(self, result):
[   11s]         """Sets the return value of work associated with the future.
[   11s]     
[   11s]         Should only be used by Executor implementations and unit tests.
[   11s]         """
[   11s]         with self._condition:
[   11s]             if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED, FINISHED}:
[   11s] >               raise InvalidStateError('{}: {!r}'.format(self._state, self))
[   11s] E               concurrent.futures._base.InvalidStateError: FINISHED: <Future at 0x7f8e1ab3fb20 state=finished raised JsonRpcInvalidRequest>
[   11s] 
[   11s] /usr/lib64/python3.8/concurrent/futures/_base.py:524: InvalidStateError
[   11s] _____________________________ test_request_cancel ______________________________
[   11s] 
[   11s] endpoint = <pyls_jsonrpc.endpoint.Endpoint object at 0x7f8e1ad6f670>
[   11s] consumer = <MagicMock id='140248312379232'>
[   11s] 
[   11s]     def test_request_cancel(endpoint, consumer):
[   11s]         future = endpoint.request('methodName', {'key': 'value'})
[   11s]         assert not future.done()
[   11s]     
[   11s]         consumer.assert_called_once_with({
[   11s]             'jsonrpc': '2.0',
[   11s]             'id': MSG_ID,
[   11s]             'method': 'methodName',
[   11s]             'params': {'key': 'value'}
[   11s]         })
[   11s]     
[   11s]         # Cancel the request
[   11s]         future.cancel()
[   11s]         consumer.assert_any_call({
[   11s]             'jsonrpc': '2.0',
[   11s]             'method': '$/cancelRequest',
[   11s]             'params': {'id': MSG_ID}
[   11s]         })
[   11s]     
[   11s]         with pytest.raises(exceptions.JsonRpcException) as exc_info:
[   11s] >           assert future.result(timeout=2)
[   11s] 
[   11s] test/test_endpoint.py:119: 
[   11s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   11s] 
[   11s] self = <Future at 0x7f8e1ab372b0 state=cancelled>, timeout = 2
[   11s] 
[   11s]     def result(self, timeout=None):
[   11s]         """Return the result of the call that the future represents.
[   11s]     
[   11s]         Args:
[   11s]             timeout: The number of seconds to wait for the result if the future
[   11s]                 isn't done. If None, then there is no limit on the wait time.
[   11s]     
[   11s]         Returns:
[   11s]             The result of the call that the future represents.
[   11s]     
[   11s]         Raises:
[   11s]             CancelledError: If the future was cancelled.
[   11s]             TimeoutError: If the future didn't finish executing before the given
[   11s]                 timeout.
[   11s]             Exception: If the call raised then that exception will be raised.
[   11s]         """
[   11s]         with self._condition:
[   11s]             if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
[   11s] >               raise CancelledError()
[   11s] E               concurrent.futures._base.CancelledError
[   11s] 
[   11s] /usr/lib64/python3.8/concurrent/futures/_base.py:430: CancelledError
[   11s] ------------------------------ Captured log call -------------------------------
[   11s] ERROR    concurrent.futures:_base.py:330 exception calling callback for <Future at 0x7f8e1ab372b0 state=cancelled>
[   11s] Traceback (most recent call last):
[   11s]   File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 328, in _invoke_callbacks
[   11s]     callback(self)
[   11s]   File "/home/abuild/rpmbuild/BUILD/python-jsonrpc-server-0.3.4/pyls_jsonrpc/endpoint.py", line 91, in callback
[   11s]     future.set_exception(JsonRpcRequestCancelled())
[   11s]   File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 539, in set_exception
[   11s]     raise InvalidStateError('{}: {!r}'.format(self._state, self))
[   11s] concurrent.futures._base.InvalidStateError: CANCELLED: <Future at 0x7f8e1ab372b0 state=cancelled>
[   11s] ___________________________ test_writer_bad_message ____________________________
[   11s] 
[   11s] wfile = <_io.BytesIO object at 0x7f8e1ab2d5e0>
[   11s] writer = <pyls_jsonrpc.streams.JsonRpcStreamWriter object at 0x7f8e1aab2580>
[   11s] 
[   11s]     def test_writer_bad_message(wfile, writer):
[   11s]         # A datetime isn't serializable(or poorly serializable),
[   11s]         # ensure the write method doesn't throw
[   11s]         import datetime
[   11s]         writer.write(datetime.datetime(
[   11s]             year=2019,
[   11s]             month=1,
[   11s]             day=1,
[   11s]             hour=1,
[   11s]             minute=1,
[   11s]             second=1,
[   11s]         ))
[   11s]     
[   11s]         if os.name == 'nt':
[   11s]             assert wfile.getvalue() == b''
[   11s]         else:
[   11s] >           assert wfile.getvalue() == (
[   11s]                 b'Content-Length: 10\r\n'
[   11s]                 b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
[   11s]                 b'\r\n'
[   11s]                 b'1546304461'
[   11s]             )
[   11s] E           AssertionError: assert b'' == b'Content-Len...r\n1546304461'
[   11s] E             Full diff:
[   11s] E             - b''
[   11s] E             + (
[   11s] E             +  b'Content-Length: 10\r\nContent-Type: application/vscode-jsonrpc; charset=ut'
[   11s] E             +  b'f8\r\n\r\n1546304461',
[   11s] E             + )
[   11s] 
[   11s] test/test_streams.py:114: AssertionError
[   11s] ------------------------------ Captured log call -------------------------------
[   11s] ERROR    pyls_jsonrpc.streams:streams.py:112 Failed to write message to output file 2019-01-01 01:01:01
[   11s] Traceback (most recent call last):
[   11s]   File "/home/abuild/rpmbuild/BUILD/python-jsonrpc-server-0.3.4/pyls_jsonrpc/streams.py", line 98, in write
[   11s]     body = json.dumps(message, **self._json_dumps_args)
[   11s] TypeError: � is not JSON serializable
[   11s] =============================== warnings summary ===============================
[   11s] test/test_endpoint.py::test_bad_message
[   11s]   /home/abuild/rpmbuild/BUILD/python-jsonrpc-server-0.3.4/pyls_jsonrpc/endpoint.py:101: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
[   11s]     log.warn("Unknown message type %s", message)
[   11s] 
[   11s] test/test_endpoint.py::test_consume_notification_method_not_found
[   11s]   /home/abuild/rpmbuild/BUILD/python-jsonrpc-server-0.3.4/pyls_jsonrpc/endpoint.py:138: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
[   11s]     log.warn("Ignoring notification for unknown method %s", method)
[   11s] 
[   11s] test/test_endpoint.py::test_consume_request_cancel_unknown
[   11s]   /home/abuild/rpmbuild/BUILD/python-jsonrpc-server-0.3.4/pyls_jsonrpc/endpoint.py:168: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
[   11s]     log.warn("Received cancel notification for unknown message id %s", msg_id)
[   11s] 
[   11s] -- Docs: https://docs.pytest.org/en/latest/warnings.html
[   11s] =================== 3 failed, 24 passed, 3 warnings in 0.20s ===================

Full build log with all details

Requesting maintenance permissions on this repo

@gatesn, in order to keep maintaining the Python language server and move forward with the transition to Python 3 (as we agreed on), I'd like to kindly ask you to grant me write permissions to this repo.

Also, it'd be great if you could also grant me admin permissions (here and in the PyLS) so I could move their CIs to Github actions. However, I'd understand if that's not possible due to company policies.

Hope to hear from you soon,
Carlos

Tests fails in Debian with python 3.8

im trying to packages python-jsonrpc-server for Debian but i get this issue on the test with python3.8
Im try to use the patch from https://git.archlinux.org/svntogit/community.git/tree/trunk/python-3.8.patch?h=packages/python-jsonrpc-server but i get this issue:

I: pybuild base:217: cd /pkg-python-jsonrpc-server/python-jsonrpc-server/.pybuild/cpython3_3.8/build; python3.8 -m pytest test
============================= test session starts ==============================
platform linux -- Python 3.8.4rc1, pytest-4.6.11, py-1.8.1, pluggy-0.13.0
rootdir: /pkg-python-jsonrpc-server/python-jsonrpc-server, inifile: setup.cfg, testpaths: test
plugins: cov-2.8.1
collected 27 items

test/test_endpoint.py ......................                             [ 81%]
test/test_streams.py ...FF                                               [100%]

=================================== FAILURES ===================================
_________________________________ test_writer __________________________________

wfile = <_io.BytesIO object at 0x7f61fd7cf1d0>
writer = <pyls_jsonrpc.streams.JsonRpcStreamWriter object at 0x7f61fd7ccdf0>

    def test_writer(wfile, writer):
        writer.write({
            'id': 'hello',
            'method': 'method',
            'params': {}
        })
    
        if os.name == 'nt':
            assert wfile.getvalue() == (
                b'Content-Length: 49\r\n'
                b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
                b'\r\n'
                b'{"id": "hello", "method": "method", "params": {}}'
            )
        else:
>           assert wfile.getvalue() == (
                b'Content-Length: 44\r\n'
                b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
                b'\r\n'
                b'{"id":"hello","method":"method","params":{}}'
            )
E           assert b'Content-Len..."params": {}}' == b'Content-Leng...,"params":{}}'
E             At index 17 diff: 57 != 52
E             Left contains 5 more items, first extra item: 58
E             Use -v to get the full diff

test/test_streams.py:90: AssertionError
___________________________ test_writer_bad_message ____________________________

wfile = <_io.BytesIO object at 0x7f61fd7b9db0>
writer = <pyls_jsonrpc.streams.JsonRpcStreamWriter object at 0x7f61fe0e23d0>

    def test_writer_bad_message(wfile, writer):
        # A datetime isn't serializable(or poorly serializable),
        # ensure the write method doesn't throw
        import datetime
        writer.write(datetime.datetime(
            year=2019,
            month=1,
            day=1,
            hour=1,
            minute=1,
            second=1,
        ))
    
        if os.name == 'nt':
            assert wfile.getvalue() == b''
        else:
>           assert wfile.getvalue() == (
                b'Content-Length: 10\r\n'
                b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
                b'\r\n'
                b'1546304461'
            )
E           AssertionError: assert b'' == b'Content-Length: 10\r\nCon...rset=utf8\r\n\r\n1546304461'
E             Right contains 88 more items, first extra item: 67
E             Use -v to get the full diff

test/test_streams.py:114: AssertionError
------------------------------ Captured log call -------------------------------
ERROR    pyls_jsonrpc.streams:streams.py:112 Failed to write message to output file 2019-01-01 01:01:01
Traceback (most recent call last):
  File "/pkg-python-jsonrpc-server/python-jsonrpc-server/.pybuild/cpython3_3.8/build/pyls_jsonrpc/streams.py", line 98, in write
    body = json.dumps(message, **self._json_dumps_args)
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable
- generated xml file: /pkg-python-jsonrpc-server/python-jsonrpc-server/.pybuild/cpython3_3.8/build/pytest.xml -

--------- coverage: platform linux, python 3.8.4-candidate-1 ---------
Name                    Stmts   Miss  Cover
-------------------------------------------
test/__init__.py            0      0   100%
test/test_endpoint.py     133      4    97%
test/test_streams.py       46      2    96%
-------------------------------------------
TOTAL                     179      6    97%
Coverage HTML written to dir htmlcov

===================== 2 failed, 25 passed in 0.40 seconds ======================
Coverage.py warning: Module pyls was never imported. (module-not-imported)
E: pybuild pybuild:352: test: plugin distutils failed with: exit code=1: cd /pkg-python-jsonrpc-server/python-jsonrpc-server/.pybuild/cpython3_3.8/build; python3.8 -m pytest test

Any idea?

Received cancel notification for unknown message

While using python-jsonrpc-server if I start typing fast in the monaco editor (which I am using coupled with monaco-languageclient), I get a flurry of warnings

WARNING - pyls_jsonrpc.endpoint - Received cancel notification for unknown message

I do see that the jedi component that I use does get invoked, but the auto-completions, linting, signature help - everything simply stops working.

Can't launch the server,help me

D:\work\onlinepythonedit\work\online_python_edit_and_run\app\languageServer> python .\python_server.py
Traceback (most recent call last):
File ".\python_server.py", line 74, in
app.listen(3000, address='127.0.0.1')
File "E:\Program Files\python\lib\site-packages\tornado\web.py", line 2116, in listen
server.listen(port, address)
File "E:\Program Files\python\lib\site-packages\tornado\tcpserver.py", line 152, in listen
self.add_sockets(sockets)
File "E:\Program Files\python\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File "E:\Program Files\python\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "E:\Program Files\python\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "E:\Program Files\python\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError

Release tarball contains incorrect version "0+unknown"

$ curl -sL https://github.com/palantir/python-jsonrpc-server/archive/0.1.0.tar.gz | tar -xzv
$ cd python-jsonrpc-server-0.1.0                                      
$ python -m venv env                                                  
$ . env/bin/activate
$ python setup.py install

$ pip list | rg jsonrpc
python-jsonrpc-server 0+unknown

When you repeat the same steps in develop branch, you correctly get version 0.1.0.

This incorrect version breaks python-language-server.

$ pyls                                                
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 581, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 898, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.7/site-packages/pkg_resources/__init__.py", line 789, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (python-jsonrpc-server 0+unknown (/usr/lib/python3.7/site-packages), Requirement.parse('python-jsonrpc-server>=0.1.0'), {'python-language-server'})

Allow any order of headers in base protocol

Hi,

Currently python-jsonrpc-server requires the Content-Length header to be sent first. I guess the following snippet is causing the issue:

        content_length = self._content_length(line)

        # Blindly consume all header lines
        while line and line.strip():
             line = self._rfile.readline()

I think it would be good to allow reading headers in any order. The LSP specification doesn't mention anything about order, even though it is listed in one, leaving it a bit open for interpretation.

Let me know if you would like a PR with a suggestion for a fix (assuming you agree with my conclusion that is).

Regards

does not support number for ID

ID can be string, number, or null. Number does not seem to be supported.

jsonrpc-plugin-854987fc66-mt9n9 main 127.0.0.1 - - [19/Feb/2021 05:15:01] code 400, message Bad request syntax ('{"method":"init","params":[{}],"id":0}')
jsonrpc-plugin-854987fc66-mt9n9 main 127.0.0.1 - - [19/Feb/2021 05:15:01] "{"method":"init","params":[{}],"id":0}" 400 -

Test test_writer_bad_message fails when not in UTC timezone

The test_writer_bad_message fails when running in a timezone other than UTC, as the timestamp() method presumes that it is local time unless a timezone is specified, and so the assert (which has assumed UTC) fails. This patch fixes this issue.

--- a/test/test_streams.py
+++ b/test/test_streams.py
@@ -119,6 +119,7 @@
         hour=1,
         minute=1,
         second=1,
+        tzinfo=datetime.timezone.utc,
     ))
 
     assert wfile.getvalue() in [

examples/langserver_ext.py processes are taking too much memory

Issue: subprocesses created from langserver_ext.py take up too much memory. Often, one process takes over 100MB. How can I reduce the memory size of each process?

I also found that the processes did not terminate when the websocket connection had closed. So the host was accumulating all of the processes until memory hit 100% and then the host crashes.

I fixed this issue by calling terminate on the subprocess inside the websocket's on_close

class PythonLanguageServer(websocket.WebSocketHandler):
    """Setup tornado websocket handler to host an external language server."""

    def open(self, *args, **kwargs):
        log.info(f"[{datetime.now().strftime('%d/%b/%Y %H:%M:%S')}] New Connection")
        print(f"[{datetime.now().strftime('%d/%b/%Y %H:%M:%S')}] New Connection")

        # Create an instance of the language server
        self.proc = process.Subprocess(["pyls"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)

        # Create a writer that formats json messages with the correct LSP headers
        self.writer = streams.JsonRpcStreamWriter(self.proc.stdin)

        # Create a reader for consuming stdout of the language server. We need to
        # consume this in another thread
        def consume():
            # Start a tornado IOLoop for reading/writing to the process in this thread
            ioloop.IOLoop()
            reader = streams.JsonRpcStreamReader(self.proc.stdout)
            reader.listen(lambda msg: self.write_message(json.dumps(msg)))

        thread = threading.Thread(target=consume)
        thread.daemon = True
        thread.start()

    def on_message(self, message):
        """Forward client->server messages to the endpoint."""
        self.writer.write(json.loads(message))  # Most memory is used by this

    def check_origin(self, origin):
        return True

    def on_close(self):
        self.proc.stdin.close()
        self.proc.stdout.close()
        self.proc.proc.terminate()

what's up,always receive warning

I'm use examples/langserver_ext.py. when i input ,always receive this warning, and it's not work,editor no response ,i need help

2020-09-22 00:02:28,387 UTC - WARNING - pyls_jsonrpc.endpoint - Received cancel notification for unknown message id 5
2020-09-22 00:02:31,268 UTC - WARNING - pyls_jsonrpc.endpoint - Received cancel notification for unknown message id 11
2020-09-22 00:02:31,271 UTC - WARNING - pyls_jsonrpc.endpoint - Received cancel notification for unknown message id 12
2020-09-22 00:03:00,532 UTC - WARNING - pyls_jsonrpc.endpoint - Received cancel notification for unknown message id 93

windows line endings support

I was messing around with pyls and realised that for some reason it didn't work on windows as it didn't recognize '\r\n' as None and so failed to work properly. I've made a PR that fixes this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.