1
|
|
|
"""Msgpack handling in the event loop pipeline.""" |
2
|
6 |
|
import logging |
3
|
|
|
|
4
|
6 |
|
from msgpack import Packer, Unpacker |
|
|
|
|
5
|
|
|
|
6
|
6 |
|
from ..compat import unicode_errors_default |
7
|
|
|
|
8
|
6 |
|
logger = logging.getLogger(__name__) |
9
|
6 |
|
debug, info, warn = (logger.debug, logger.info, logger.warning,) |
10
|
|
|
|
11
|
|
|
|
12
|
6 |
|
class MsgpackStream(object): |
13
|
|
|
|
14
|
|
|
"""Two-way msgpack stream that wraps a event loop byte stream. |
15
|
|
|
|
16
|
|
|
This wraps the event loop interface for reading/writing bytes and |
17
|
|
|
exposes an interface for reading/writing msgpack documents. |
18
|
|
|
""" |
19
|
|
|
|
20
|
6 |
|
def __init__(self, event_loop): |
21
|
|
|
"""Wrap `event_loop` on a msgpack-aware interface.""" |
22
|
|
|
self._event_loop = event_loop |
23
|
|
|
self._packer = Packer(unicode_errors=unicode_errors_default) |
24
|
|
|
self._unpacker = Unpacker() |
25
|
|
|
self._message_cb = None |
26
|
|
|
|
27
|
6 |
|
def threadsafe_call(self, fn): |
28
|
|
|
"""Wrapper around `BaseEventLoop.threadsafe_call`.""" |
29
|
|
|
self._event_loop.threadsafe_call(fn) |
30
|
|
|
|
31
|
6 |
|
def send(self, msg): |
32
|
|
|
"""Queue `msg` for sending to Nvim.""" |
33
|
|
|
debug('sent %s', msg) |
34
|
|
|
self._event_loop.send(self._packer.pack(msg)) |
35
|
|
|
|
36
|
6 |
|
def run(self, message_cb): |
37
|
|
|
"""Run the event loop to receive messages from Nvim. |
38
|
|
|
|
39
|
|
|
While the event loop is running, `message_cb` will be called whenever |
40
|
|
|
a message has been successfully parsed from the input stream. |
41
|
|
|
""" |
42
|
|
|
self._message_cb = message_cb |
43
|
|
|
self._event_loop.run(self._on_data) |
44
|
|
|
self._message_cb = None |
45
|
|
|
|
46
|
6 |
|
def stop(self): |
47
|
|
|
"""Stop the event loop.""" |
48
|
|
|
self._event_loop.stop() |
49
|
|
|
|
50
|
6 |
|
def _on_data(self, data): |
51
|
|
|
self._unpacker.feed(data) |
52
|
|
|
while True: |
53
|
|
|
try: |
54
|
|
|
debug('waiting for message...') |
55
|
|
|
msg = next(self._unpacker) |
56
|
|
|
debug('received message: %s', msg) |
57
|
|
|
self._message_cb(msg) |
58
|
|
|
except StopIteration: |
59
|
|
|
debug('unpacker needs more data...') |
60
|
|
|
break |
61
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.