@@ -127,15 +127,22 @@ def _discover_functions(self, obj, handlers, plugin_path):
127
127
def predicate (o ):
128
128
return hasattr (o , '_nvim_rpc_method_name' )
129
129
specs = []
130
+ objenc = getattr (obj , '_nvim_encoding' , None )
130
131
for _ , fn in inspect .getmembers (obj , predicate ):
132
+ enc = getattr (fn , '_nvim_encoding' , objenc )
131
133
if fn ._nvim_bind :
132
134
# bind a nvim instance to the handler
133
135
fn2 = functools .partial (fn , self ._configure_nvim_for (fn ))
134
136
# copy _nvim_* attributes from the original function
135
- for attr in dir (fn ):
136
- if attr .startswith ('_nvim_' ):
137
- setattr (fn2 , attr , getattr (fn , attr ))
137
+ self ._copy_attributes (fn , fn2 )
138
138
fn = fn2
139
+ decodehook = self ._decodehook_for (enc )
140
+ if decodehook is not None :
141
+ decoder = lambda fn , hook , * args : fn (* hook .walk (args ))
142
+ fn2 = functools .partial (decoder , fn , decodehook )
143
+ self ._copy_attributes (fn , fn2 )
144
+ fn = fn2
145
+
139
146
# register in the rpc handler dict
140
147
method = fn ._nvim_rpc_method_name
141
148
if fn ._nvim_prefix_plugin_path :
@@ -150,25 +157,36 @@ def predicate(o):
150
157
raise Exception (('Notification handler for "{0}" is ' +
151
158
'already registered' ).format (method ))
152
159
self ._notification_handlers [method ] = fn
153
- if hasattr (fn , 'nvim_rpc_spec ' ):
154
- specs .append (fn .nvim_rpc_spec )
160
+ if hasattr (fn , '_nvim_rpc_spec ' ):
161
+ specs .append (fn ._nvim_rpc_spec )
155
162
handlers .append (fn )
156
163
if specs :
157
164
self ._specs [plugin_path ] = specs
158
165
166
+ def _copy_attributes (self , fn , fn2 ):
167
+ # Copy _nvim_* attributes from the original function
168
+ for attr in dir (fn ):
169
+ if attr .startswith ('_nvim_' ):
170
+ setattr (fn2 , attr , getattr (fn , attr ))
171
+
159
172
def _on_specs_request (self , path ):
160
173
if IS_PYTHON3 and isinstance (path , bytes ):
161
174
path = path .decode (self ._nvim_encoding )
162
175
return self ._specs .get (path , [])
163
176
164
- def _configure_nvim_for (self , obj ):
165
- # Configure a nvim instance for obj(checks encoding configuration)
166
- nvim = self .nvim
167
- encoding = getattr (obj , '_nvim_encoding' , None )
177
+ def _decodehook_for (self , encoding ):
168
178
if IS_PYTHON3 and encoding is None :
169
179
encoding = True
170
180
if encoding is True :
171
181
encoding = self ._nvim_encoding
172
182
if encoding :
173
- nvim = nvim .with_hook (DecodeHook (encoding ))
183
+ return DecodeHook (encoding )
184
+
185
+ def _configure_nvim_for (self , obj ):
186
+ # Configure a nvim instance for obj (checks encoding configuration)
187
+ nvim = self .nvim
188
+ encoding = getattr (obj , '_nvim_encoding' , None )
189
+ hook = self ._decodehook_for (encoding )
190
+ if hook is not None :
191
+ nvim = nvim .with_hook (hook )
174
192
return nvim
0 commit comments