Skip to content

Commit 5560d63

Browse files
committed
Use &encoding for msgpack Packer
- This commit disables automatic encoding of Unicode strings until &encoding is retrieved, and then resets the packer to use &encoding - Previously the msgpack Packer always encoded Unicode as utf-8
1 parent 44f850d commit 5560d63

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

neovim/api/nvim.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def from_session(cls, session):
4444
creating specialized objects from Nvim remote handles.
4545
"""
4646
session.error_wrapper = lambda e: NvimError(e[1])
47-
channel_id, metadata = session.request('vim_get_api_info')
47+
channel_id, metadata = session.request(b'vim_get_api_info')
48+
49+
encoding = session.request(b'vim_get_option', b'encoding')
50+
session._async_session._msgpack_stream.set_packer_encoding(encoding)
4851

4952
if IS_PYTHON3:
5053
hook = DecodeHook()

neovim/msgpack_rpc/msgpack_stream.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ def __init__(self, event_loop):
2121
"""Wrap `event_loop` on a msgpack-aware interface."""
2222
self._event_loop = event_loop
2323
self._posted = deque()
24-
self._packer = Packer(use_bin_type=True)
24+
self._packer = Packer(use_bin_type=True, encoding=None)
2525
self._unpacker = Unpacker()
2626
self._message_cb = None
2727
self._stopped = False
2828

29+
def set_packer_encoding(self, encoding):
30+
"""Switch encoding for Unicode strings."""
31+
self._packer = Packer(use_bin_type=True, encoding=encoding)
32+
2933
def post(self, msg):
3034
"""Post `msg` to the read queue of the `MsgpackStream` instance.
3135

0 commit comments

Comments
 (0)