+
    8Li.                     r   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
 ^ RIHt ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ RIHtHt Rt]P8                  ! ]4      t]P>                  ]P@                  ]PB                  ]PD                  3w  tt t!t#R
/ RR^/R/ /t$R R lt% ! R R	]&4      t'R# )z*Implements a Nvim host for python plugins.N)partial)
format_exc)AnySequence)Nvimdecode_if_byteswalk)ErrorResponse)script_host)format_exc_skipget_client_infoHostpollspecsnargsshutdownc                0    V ^8  d   QhR\         R\         /# )   pathnamestr)formats   "4/usr/lib/python3/dist-packages/pynvim/plugin/host.py__annotate__r      s     ) ) )C )    c                    V'       g   \        R4      h\        P                  P                  V 4       \        P
                  ! V4      # )a  Import python module `name` from a known file path or module directory.

The path should be the base directory from which the module can be imported.
To support python 3.12, the use of `imp` should be avoided.
@see https://docs.python.org/3.12/whatsnew/3.12.html#imp
zMissing module name.)
ValueErrorsysr   append	importlibimport_module)r   r   s   &&r   _handle_importr"      s4     /00HHOOD""4((r   c                      a  ] tR t^,t o RtV 3R lR ltV 3R lR ltV 3R lR ltR tV 3R	 lR
 lt	R t
R tV 3R lR ltV 3R lR ltR tV 3R lR ltV 3R lR ltR tR tR tR tR tRtV tR# )r   zNvim host for python plugins.

Takes care of loading/unloading plugins and routing msgpack-rpc
requests/notifications to the appropriate handlers.
c                    < V ^8  d   QhRS[ /# )r   nvim)r   )r   __classdict__s   "r   r   Host.__annotate__4   s     $ $T $r   c                    Wn         / V n        / V n        / V n        RV P                  /V n        RR RV P                  RV P                  /V n        RV n	        R# )z+Set handlers for plugin_load/plugin_unload.nvim_error_eventr   c                      R # )ok r,   r   r   <lambda>Host.__init__.<locals>.<lambda>>   s    Dr   r   r   TN)
r%   _specs_loaded_load_errors_on_error_event_notification_handlers_on_specs_requestr   _request_handlers_decode_default)selfr%   s   &&r   __init__Host.__init__4   sa    	 4 4'
# LT++"
  $r   c                $   < V ^8  d   QhRS[ RR/# )r   msgreturnNr   )r   r&   s   "r   r   r'   E   s     . . . .r   c                @    V P                   P                  VR R7       R# )Tasync_N)r%   	err_write)r7   r;   s   &&r   _on_async_errHost._on_async_errE   s    		C-r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   kindr;   r<   N)r   r   )r   r&   s   "r   r   r'   I   s"      C c d r   c                    R P                  V P                  \        V4      4      pV P                  P	                  VRR7       V# )z&{}: Async request caused an error:
{}
Tr>   )r   r   r   r%   r@   )r7   rD   r;   errmsgs   &&& r   r2   Host._on_error_eventI   s>     <BBIIs+-		F40r   c                   a a S P                   P                  S P                  S P                  VV 3R lS P                  R7       R# )z;Start listening for msgpack-rpc requests and notifications.c                  &   < SP                  S 4      # )N)_load)pluginsr7   s   r   r-   Host.start.<locals>.<lambda>U   s    4::g#6r   )err_cbN)r%   run_loop_on_request_on_notificationrA   )r7   rK   s   ffr   start
Host.startQ   s7    		4++006"&"4"4 	 	6r   c                   < V ^8  d   QhRR/# r   r<   Nr,   )r   r&   s   "r   r   r'   X   s      $ r   c                Z    V P                  4        V P                  P                  4        R# )zShutdown the host.N)_unloadr%   	stop_loop)r7   s   &r   r   Host.shutdownX   s    		r   c                H   V F=  pVP                   p	VP                  '       d   V P                  V	 K0  V P                  V	 K?  	  V! V P	                  V4      4      p
V P                  WVR 4       V'       d   V P                  V,          ! V!  # V P                  V,          ! V!  # )F)_nvim_registered_name_nvim_rpc_syncr5   r3   _configure_nvim_for_discover_functions)r7   clsdelayed_handlersr   syncmodule_handlersr   argshandlermethod_nameplugins   &&&&&&&*   r   _wrap_delayed_functionHost._wrap_delayed_function]   s     (G!77K%%%**;7//< ( T--c23 	  $F))$/66..t4d;;r   c                h   V'       d   \        \        \        VR 7      V4      pVe   VP                  ^ V4        V! V!  #   \         df    T'       d'   RP                  YV\        ^4      4      p\        T4      hRP                  YV\        ^4      4      pT P                  TR,           4        R# i ; i))modeNz+error caught in request handler '{} {}':
{}z)error caught in async handler '{} {}'
{}

)	r   r   r   insert	Exceptionr   r   r	   rA   )r7   fnr`   decode	nvim_bindr   rb   r;   s   &&&&&&* r   _wrap_functionHost._wrap_functionq   s    f=tDD KK9%
	/t9 	/Et?1+=> #C((Dt?1+=> ""3:.	/s   A B1AB10B1c                :   < V ^8  d   QhRS[ RS[S[,          RR/# r   r   rb   r<   Nr   r   r   )r   r&   s   "r   r   r'      s&       8C= T r   c                    \        V4      pV P                  P                  VR4      pV'       g   V P                  VR4      p \	        V4      h V! V!  p V# )zHandle a msgpack-rpc request.Nrequest)r   r5   get_missing_handler_errorr	   )r7   r   rb   rc   r;   rvs   &&&   r   rO   Host._on_request   s[    t$((,,T48--dI>C$$d^	r   c                :   < V ^8  d   QhRS[ RS[S[,          RR/# rs   rt   )r   r&   s   "r   r   r'      s&      S  $ r   c                    \        V4      pV P                  P                  VR4      pV'       g.   V P                  VR4      p V P	                  VR,           4       R#  V! V!   R# )z"Handle a msgpack-rpc notification.Nnotificationrj   )r   r3   rw   rx   rA   )r7   r   rb   rc   r;   s   &&&  r   rP   Host._on_notification   s[    t$--11$=--dNCCsTz*r   c                    R P                  W!4      p\        P                  ! RV4      pV'       d?   V P                  P	                  VP                  ^4      4      pVe   VR,           V,           pV# )z!no {} handler registered for "{}"z(.+):[^:]+:[^:]+rj   )r   rematchr1   rw   group)r7   r   rD   r;   	pathmatchloader_errors   &&&   r   rx   Host._missing_handler_error   s^    188DHH0$7	,,001CDL'Dj</
r   c                4   < V ^8  d   QhRS[ S[,          RR/# )r   rK   r<   N)r   r   )r   r&   s   "r   r   r'      s     +: +:Xc] +:t +:r   c           
        RpV EF   p\         P                  ! \        P                  P	                  V4      4      P                  4       pRpW0P                  9   d    KZ   VR8X  d
   \        pRpMP\        P                  P                  \        P                  P                  V4      ^ ,          4      w  rg\        Wg4      p. pV P                  WXV4       V P                  WXVR4       V'       g    K  RVRV/V P                  V&   EK  	  \'        V4      ^8X  d   V'       d   RMR	p
\)        V
R
\*        4      pV^ ,          V n        V P.                  P0                  P2                  ! VRR/  R#   \         dK   p	RP                  \        T	4      P                   Y9\#        ^4      4      p Y@P$                  T&    Rp	?	EK  Rp	?	ii ; i)zLoad the remote plugins and register handlers defined in the plugins.

Args:
    plugins: List of plugin paths to rplugin python modules
        registered by remote#host#RegisterPlugin('python3', ...)
        (see the generated rplugin.vim manifest)
FNzscript_host.pyThandlersmodulez*Encountered {} loading plugin at {}: {}
{}zscript-hostzrplugin-hosthostr?   )pathlibPathosr   normpathas_posixr0   r
   splitsplitextr"   _discover_classesr]   rl   r   type__name__r   r1   lenr   host_method_specr   r%   apiset_client_info)r7   rK   
has_scriptr   errr   	directoryr   r   erD   infos   &&          r   rJ   
Host._load   sx    
D<< 0 0 67@@BDC||#.++(F!%J&(ggmmBGG4D4DT4J14M&NOI+I<F&&v>((4G&0(Hf%MT"+ : "%W!2z# 	tV-=>G			%%t9D9  .DtAw//*Q-H *-!!$''.s    BE-2E--G8>F==Gc                   < V ^8  d   QhRR/# rT   r,   )r   r&   s   "r   r   r'      s       r   c                6   V P                   P                  4        Fl  w  rVR ,          pV FX  pVP                  p\        VR4      '       d
   V! 4        K*  VP                  '       d   V P
                  V KK  V P                  V KZ  	  Kn  	  / V n        / V n         R# )r   _nvim_shutdown_hookN)r0   itemsrZ   hasattrr[   r5   r3   r/   )r7   r   re   r   rc   rd   s   &     r   rV   Host._unload   s     LL..0LDj)H#%;;7$9::I+++..{;33K@ $ 1 r   c                    \         P                  ! V\         P                  4       F-  w  rE\        VR R4      '       g   K  V P	                  WRVR4       K/  	  R# )_nvim_pluginFTN)inspect
getmembersisclassgetattrr]   )r7   r   r   plugin_path_r^   s   &&&&  r   r   Host._discover_classes   sA    ((AFAsNE22((TJ Br   c           
        R  p. p. p\        VRV P                  4      p\        P                  ! W4       EF  w  rV
P                  pV
P
                  '       d   RP                  W;4      pV
P                  pV'       d   \        V P                  VWkVW#4      pMJ\        V
RV4      pRpV
P                  '       d   V P                  V
4      p\        V P                  V
WW4      pV P                  W4       Wn        V'       d:   WP                  9   d   \!        RP                  V4      4      hWP                  V&   M8WP"                  9   d   \!        RP                  V4      4      hWP"                  V&   \%        V
R4      '       d   VP'                  V
P(                  4       VP'                  V4       VP'                  V4       EK  	  V'       d   WpP*                  V&   R# R# )c                     \        V R 4      # )_nvim_rpc_method_name)r   )os   &r   	predicate+Host._discover_functions.<locals>.predicate   s    1566r   _nvim_decodez{}:{}N_nvim_rpc_specz.Request handler for "{}" is already registeredz3Notification handler for "{}" is already registered)r   r6   r   r   r   _nvim_prefix_plugin_pathr   r[   r   rf   
_nvim_bindr\   rp   _copy_attributesrZ   r5   rl   r3   r   r   r   r/   )r7   objr   r   delayr   cls_handlersr   	objdecoder   rm   methodr`   
fn_wrappedrn   ro   s   &&&&&           r   r]   Host._discover_functions   s   	7 C1E1EF	''7EA--F*** <$$D$T%@%@#%14%-<
 !^Y? 	=== $ 8 8 <I$T%8%8"%)9F
!!"1/5,333# &<=CVF^M M1;&&v.888# &<=CVF^M M6@++F3r+,,R../OOJ'
+C 8D ',KK$ r   c           	         \        V4       F1  pVP                  R 4      '       g   K  \        W#\        W4      4       K3  	  R# )_nvim_N)dir
startswithsetattrr   )r7   rm   fn2attrs   &&& r   r   Host._copy_attributes  s.    GDx((72#45 r   c                X   \        V4      p\        P                  ! \        P                  P                  V4      4      P                  4       pWP                  9   d4   V P                  P                  V P                  V,          R ,           4       V P                  P                  V^ 4      # )rj   )r   r   r   r   r   r   r   r1   r%   	out_writer/   rw   )r7   r   s   &&r   r4   Host._on_specs_request  su    t$||BGG,,T23<<>$$$II 1 1$ 7$ >?{{tQ''r   c                ~    V P                   p\        VR V P                  4      pV'       d   VP                  V4      pV# )r   )r%   r   r6   with_decode)r7   r   r%   rn   s   &&  r   r\   Host._configure_nvim_for%  s7    yynd.B.BC##F+Dr   )r6   r1   r0   r3   r5   r/   r   r%   N)r   
__module____qualname____firstlineno____doc__r8   rA   r2   rQ   r   rf   rp   rO   rP   rx   rJ   rV   r   r]   r   r4   r\   __static_attributes____classdictcell__)r&   s   @r   r   r   ,   s     $ $". . 6 
<(/" " +: +:Z K*-X6( r   )r   )(r   r    r   loggingr   os.pathr   r   r   	functoolsr   	tracebackr   typingr   r   
pynvim.apir   r   r   pynvim.msgpack_rpcr	   pynvim.pluginr
   pynvim.utilr   r   __all__	getLoggerr   loggererrordebugr   warningwarnr   r"   objectr   r,   r   r   <module>r      s    0    	   	 
      2 2 , % 8
			8	$"LL&,,"NN- udD B'1z2F )6 r   