
    ue;                     V   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlZd dlmZ d dlmZ d dlmZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZmZ  e j@                  e!      Z"dZ#dZ$dZ%dZ&dZ' G d dejP                        Z)d Z*d Z+d Z, G d de      Z-d Z.d Z/y)    N)partial)AnyDictList)MethodDispatcher)Endpoint)JsonRpcStreamReaderJsonRpcStreamWriter   )_utilslspuris)__version__)config)CellDocumentNotebook	Workspaceg      ?
   @   )z.pyz.pyi)zpycodestyle.cfgz	setup.cfgztox.iniz.flake8c                   ,     e Zd ZdZdZ fdZd Z xZS )_StreamHandlerWrapperzAA wrapper class that is used to construct a custom handler class.Nc                 x    t         |           | j                  | j                  | j                        | _        y N)supersetupDELEGATE_CLASSrfilewfiledelegate)self	__class__s    2/usr/lib/python3/dist-packages/pylsp/python_lsp.pyr   z_StreamHandlerWrapper.setup%   s(    ++DJJ

C    c                     	 | j                   j                          | j                          y # t        $ r=}t        j                  dk(  r t        |t              r|j                  dk(  r	 Y d }~Rd }~ww xY w)NntiF'  )	r    startOSErrorosname
isinstanceWindowsErrorwinerrorSHUTDOWN_CALL)r!   es     r#   handlez_StreamHandlerWrapper.handle)   s]    	MM! 	  	ww$ a.1::3F	s   - 	A33A..A3)__name__
__module____qualname____doc__r    r   r0   __classcell__r"   s   @r#   r   r       s    KHD
r$   r   c           	      :   t        |t              st        d      fd}t        |j                  dz   t
        ft        ||      t        ||      d      }t        j                  | |f|d      d_	        	 j                          j                          t        j                  d	|j                  | |       j                          t        j                  d
       j                          y # t        j                  d
       j                          w xY w)N4Handler class must be an instance of PythonLSPServerc                     | rFt         j                  d       t        j                  j                        }|j                          y y )NzShutting down server)target)logdebug	threadingThreadshutdownr'   )check_parent_processargsstop_threadservers      r#   shutdown_serverz.start_tcp_lang_server.<locals>.shutdown_server:   s8    II,-#**&//BK	  r$   Handler)r@   )r   r.   F)bind_and_activateTzServing %s on (%s, %s)zShutting down)
issubclassPythonLSPServer
ValueErrortyper1   r   r   socketserver	TCPServerallow_reuse_addressserver_bindserver_activater;   infoserve_foreverserver_close)	bind_addrportr@   handler_classrD   wrapper_classrC   s         @r#   start_tcp_lang_serverrW   6   s    m_5OPP  *	 %4H %_6JK		
	M ##	D=EF "&F )=+A+A9dS! 	!s   ;AC3 3'Dc                     t        |t              st        d      t        j	                  d|j
                          || ||      }|j                          y )Nr8   zStarting %s IO language server)rG   rH   rI   r;   rP   r1   r'   )r   r   r@   rU   rC   s        r#   start_io_lang_serverrY   \   sE    m_5OPPHH-}/E/EF5%)=>F
LLNr$   c                 6   	
 t        t              st        d      	 dd lddlm} dd l
 |d      5 		fdfd 
fd	}j                   |              d d d        y # t        $ r}t        d      |d }~ww xY w# 1 sw Y   y xY w)
Nr8   r   )ThreadPoolExecutorzPwebsocket modules missing. Please run pip install 'python-lsp-server[websockets]r   max_workersc           	        K   t         j                  d       t        
|       } 	d d |      }| 2 3 d {   }	 t         j                  d       t        j                  |      }j                         }|j                  |j                  |       d {    j7 e7 # t        $ r*}t         j                  d|t        |             Y d }~d }~ww xY w6 y w)NzCreating LSP object)	websocket)rxtxconsumerr@   z/consuming payload and feeding it to LSP handlerz Failed to process request %s, %s)r;   r<   r   jsonloadsget_running_looprun_in_executorconsume	Exception	exceptionstr)r_   response_handlerpylsp_handlermessagerequestloopr/   asyncior@   rU   send_messagetpools          r#   pylsp_wsz&start_ws_lang_server.<locals>.pylsp_wsu   s     II+,  '|yI *)%9	M "+ W WgWIIOP"jj1G"335D..um6K6KWUUUW
 V  WMM"DgsSTvVVW "+s[   1CCBCCAB"B B"CC B""	C+ CCCCc                     	 t        j                  | d      }j                  |j                  |             y# t        $ r*}t
        j                  d| t        |             Y d}~yd}~ww xY w)zQHandler to send responses of  processed requests to respective web socket clientsF)ensure_asciizFailed to write message %s, %sN)rc   dumpsrunsendrh   r;   ri   rj   )rm   r_   payloadr/   rp   s       r#   rq   z*start_ws_lang_server.<locals>.send_message   sX    Q**W5AINN734 Q>QPPQs   7; 	A. A))A.c                     K   j                        4 d {     j                          d {    d d d       d {    y 7 -7 7 	# 1 d {  7  sw Y   y xY ww)N)rT   )serveFuture)rp   rT   rs   
websocketss   r#   
run_serverz(start_ws_lang_server.<locals>.run_server   s]     !''t'< ' 'nn&&&' ' '&' ' ' 'sS   A$A	A$AAAA$AA$AA$A!AA!A$)	rG   rH   rI   rp   concurrent.futuresr[   r}   ImportErrorrw   )rT   r@   rU   r[   r/   r~   rp   rs   rq   rr   r}   s   ```   @@@@@r#   start_ws_lang_serverr   d   s    m_5OPP9 
	+ '"u	W 	W0	Q	'
 	JL!O'" '"  ^
	
'" '"s"   A2 -B2	B;BBBc                       e Zd ZdZ	 dBdddZd Zd Z fdZd Zd	 Z	d
 Z
d ZdCdZd Z	 	 	 	 	 dDdZd ZdededefdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej>                  e d      d         Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(	 dEd(Z)	 dEd)Z*	 dEd*Z+dCd+Z,dCd,Z-	 dEd-Z.dCd.Z/	 dFd/Z0dCd0Z1dCd1Z2dEd2Z3dCd3Z4dEd4Z5	 dEd5Z6dEd6Z7dCd7Z8dEd8Z9	 dFd9Z:dCd:Z;	 dFd;Z<	 dFd<Z=	 dEd=Z>dCd>Z?dCd?Z@dCd@ZAdEdAZB xZCS )GrH   zImplementation of the Microsoft VSCode Language Server Protocol
    https://github.com/Microsoft/language-server-protocol/blob/master/versions/protocol-1-x.md
    N)endpoint_clsc                |   d | _         d | _        d | _        d | _        i | _        i | _        || _        |t        |      | _        nd | _        |t        |      | _
        nd | _
        |xs t        }|) || | j                  j                  t              | _        n || |t              | _        g | _        d| _        y )Nr\   F)	workspacer   root_uriwatching_thread
workspacesuri_workspace_mapper_check_parent_processr	   _jsonrpc_stream_readerr
   _jsonrpc_stream_writerr   writeMAX_WORKERS	_endpoint_dispatchers	_shutdown)r!   r`   ra   r@   rb   r   s         r#   __init__zPythonLSPServer.__init__   s     #$&!%9">*=b*AD'*.D'>*=b*AD'*.D'#/x )d1177[DN *$kRDNr$   c                 b    | j                   j                  | j                  j                         y)zEntry point for the server.N)r   listenr   rg   )r!   s    r#   r'   zPythonLSPServer.start   s     ##**4>>+A+ABr$   c                 :    | j                   j                  |       y)zGEntry point for consumer based server. Alternative to stream listeners.N)r   rg   )r!   rm   s     r#   rg   zPythonLSPServer.consume   s     	w'r$   c                     | j                   r|dk7  rt        j                  d|       d}	 t        |   |      S # t
        $ r5 | j                  D ]  }	 ||   c cY S # t
        $ r Y w xY w Y t               w xY w)z:Override getitem to fallback through multiple dispatchers.exitz,Ignoring non-exit method during shutdown: %sinvalid_request_after_shutdown)r   r;   r<   r   __getitem__KeyErrorr   )r!   item
dispatcherr"   s      r#   r   zPythonLSPServer.__getitem__   s    >>dfnIIDdK3D	7&t,, 	"// 
%d++  j	s3   ; A9AA9	A)&A9(A))A98A9c                 p    | j                   j                         D ]  }|j                           d| _        y )NT)r   valuescloser   )r!   _kwargsr   s      r#   
m_shutdownzPythonLSPServer.m_shutdown   s/    //1 	IOO	r$   c                 @    dt         j                  j                  ddiS )Nerrorz%Requests after shutdown are not valid)coderm   )r   
ErrorCodesInvalidRequestr!   r   s     r#    m_invalid_request_after_shutdownz0PythonLSPServer.m_invalid_request_after_shutdown   s$    55B
 	
r$   c                     | j                   j                          | j                  | j                  j                          | j                  | j                  j                          y y r   )r   r?   r   r   r   r   s     r#   m_exitzPythonLSPServer.m_exit   sS    !&&2''--/&&2''--/ 3r$   c                     t        j                  || j                        }| j                  j                  || j                        S r   )r   match_uri_to_workspacer   getr   )r!   uriworkspace_uris      r#   _match_uri_to_workspacez'PythonLSPServer._match_uri_to_workspace   s3    55c4??K""=$..AAr$   c                     | j                  |      }|r|j                  |      nd}| j                  j                  j	                  || j                  j
                        } |d| j                  ||d|S )zJCalls hook_name and returns a list of results from all registered handlersN)r   r   document )r   get_documentr   plugin_managersubset_hook_callerdisabled_plugins)r!   	hook_namedoc_urikwargsr   dochook_handlerss          r#   _hookzPythonLSPServer._hook   sv    009	18i$$W-d22EEt{{33
  
;;)c
EK
 	
r$   c                 r   i dddddidddgdd	dd
dddddddddt        | j                  d            iddddddddddg didt        j                  j                  ddidddddddigigid d!ddd"id#t        | j                  d$            i}t        j                  d%|       |S )&NcodeActionProviderTcodeLensProviderresolveProviderFcompletionProvider.)r   triggerCharactersdocumentFormattingProviderdocumentHighlightProviderdocumentRangeFormattingProviderdocumentSymbolProviderdefinitionProviderexecuteCommandProvidercommandspylsp_commandshoverProviderreferencesProviderrenameProviderfoldingRangeProvidersignatureHelpProviderr   )(,=textDocumentSyncincludeText)changesave	openClosenotebookDocumentSyncnotebookSelectorcellslanguagepythonr   workspaceFolders)	supportedchangeNotificationsexperimentalpylsp_experimental_capabilitieszServer capabilities: %s)flattenr   r   TextDocumentSyncKindINCREMENTALmerger;   rP   )r!   server_capabilitiess     r#   capabilitieszPythonLSPServer.capabilities  s   $
 $$
!5!$

 !#'&)U#$
 )$$
 ($
 .t$
 %d$
 !$$
 %GDJJ/?$@A'$
" T#$
$ !$%$
& d'$
( #D)$
* $&9?%K+$
, 22>>!4 "!-$
: #"gX0F/G%H$I%;$
@ "$t$TA$
F E$**-N"OPG$
J 	*,?@""r$   c           	      \   
 t         j                  d||||       ||t        j                  |      nd} j                  j                   j                  d        | _        t        j                  ||xs i ||j                  di              _        t        | j                   j                         _         j                   j                  |<   |r|D ]  }|d   }||k(  rt        j                  | j                  j                   j                  j                   j                  j                        }	|	j!                   j                  j"                         t        | j                  |	       j                  |<     j%                  d       _         j%                  d        j(                  r\|Z j*                  N 
fd
t-        j.                  
|f       _        d	 j*                  _         j*                  j3                           j5                         d
t6        ddS )Nz,Language server initialized with %s %s %s %s r   r   pylsp_dispatcherspylsp_initializec                     t        j                  |       s't        j                  d|        j	                          y t        j                  t        | g      j                          y )Nz(parent process %s is not alive, exiting!)rA   )	r   is_process_aliver;   rP   r   r=   TimerPARENT_PROCESS_WATCH_INTERVALr'   )pidr!   watch_parent_processs    r#   r   z:PythonLSPServer.m_initialize.<locals>.watch_parent_processb  sH    ..s3HHGMKKMOO57KSVRWegr$   )r:   rA   Tpylsp)r*   version)r   
serverInfo)r;   r<   r   from_fs_pathr   popr   r   Configr   r   r   r   
_init_opts_process_id_capabilitiesupdate	_settingsr   r   r   r   r=   r>   daemonr'   r   r   )r!   	processIdrootUrirootPathinitializationOptionsr   r   folderr   workspace_configr   s   `         @r#   m_initializezPythonLSPServer.m_initialize-  s    			:!	
 ?5=5Id''1rGDMM40mm!'RKK+	
 #7DNNDKKH#'>> * XUm'>#)==KK**KK++KK--	$  !''(=(=>'0dnnFV'W$X !JJ':;

%& &&%$$, $-#3#3+9,$D  +/D  '  &&( !--/&
 	
r$   c                 &    | j                  d       y )Npylsp_initializedr   r   s     r#   m_initializedzPythonLSPServer.m_initializedz  s    

&'r$   r   rangecontextc                 >    t        | j                  d|||            S )Npylsp_code_actions)r  r  r   r   )r!   r   r  r  s       r#   code_actionszPythonLSPServer.code_actions}  s$    JJ+WE7JS
 	
r$   c                 8    t        | j                  d|            S )Npylsp_code_lensr  r!   r   s     r#   	code_lenszPythonLSPServer.code_lens  s    tzz"3W=>>r$   c                    | j                  |      }|j                  |      }d }t        |t              r,|j	                  |j
                        }|j                  |      }| j                  d|||      }dt        |      dS )Npylsp_completions)positionignored_namesF)isIncompleteitems)	r   r   r+   r   get_maybe_documentnotebook_uri
jedi_namesr   r   )r!   r   r  r   r   r  notebook_documentcompletionss           r#   r  zPythonLSPServer.completions  s    009	))'2h% ) < <X=R=R S-88AMjj8= ! 
 !&0DEEr$   c                 n    |j                  di       j                  dd       }| j                  d||      S )Ndatar   pylsp_completion_item_resolve)completion_item)r   r   )r!   r#  r   s      r#   completion_item_resolvez'PythonLSPServer.completion_item_resolve  s>    !%%fb155iFzz+Wo  
 	
r$   c                 <    t        | j                  d||            S )Npylsp_definitionsr  r  r!   r   r  s      r#   definitionszPythonLSPServer.definitions  s    tzz"5wzRSSr$   c                 8    t        | j                  d|            S )Npylsp_document_symbolsr  r  s     r#   document_symbolsz PythonLSPServer.document_symbols  s    tzz":GDEEr$   c                 &    | j                  d|      S )Npylsp_document_did_saver	  r  s     r#   document_did_savez!PythonLSPServer.document_did_save  s    zz3W==r$   c                 *    | j                  d||      S )Npylsp_execute_command)command	argumentsr	  r!   r2  r3  s      r#   execute_commandzPythonLSPServer.execute_command  s    zz17izXXr$   c                       fdS )Nc                  ,    j                  d       S )Npylsp_format_document)optionsr	  )r   r9  r!   s   r#   <lambda>z1PythonLSPServer.format_document.<locals>.<lambda>  s    tzz"97GzT r$   r   )r!   r   r9  s   ```r#   format_documentzPythonLSPServer.format_document  s	    TTr$   c                 ,    | j                  d|||      S )Npylsp_format_range)r  r9  r	  )r!   r   r  r9  s       r#   format_rangezPythonLSPServer.format_range  s    zz.ugzVVr$   c                 D    t        | j                  d||            xs d S )Npylsp_document_highlightr'  r  r(  s      r#   	highlightzPythonLSPServer.highlight  s'    DJJ97XJVW 	
r$   c                 6    | j                  d||      xs ddiS )Npylsp_hoverr'  contentsr   r	  r(  s      r#   hoverzPythonLSPServer.hover  s"    zz-8zDXUWHXXr$   )keyed_byc                     | j                  |      }|j                  j                  |d       }t        |t              r| j                  |||       y t        |t              r| j                  ||       y y )Nis_saved)r   	documentsr   r+   r   _lint_text_documentr   _lint_notebook_document)r!   r   rI  r   document_objects        r#   lintzPythonLSPServer.lint  sj     009	#--11'4@ox0$$Wi($K2(()D 3r$   c           
      ^    |j                  |t        | j                  d||                   y )N
pylsp_lintrH  )publish_diagnosticsr   r   )r!   r   r   rI  s       r#   rK  z#PythonLSPServer._lint_text_document  s)    %%WTZZgZQR	
r$   c                     t        t        j                               }g }d}d}|j                  D ]u  }|d   }|j	                  |      }	|	j
                  }
||||
z   dz
  |	j                  d}|j                  |       |dk(  r|	j                  }n|d|	j                  z   z  }||
z  }w |j                  ||       	 t        | j                  d|d	            }|D ]z  }g }|D ]\  }|d
   d   d   }|d
   d   d   }||d   kD  s||d   k  r*||d   z
  |d
   d   d<   ||d   z
  |d
   d   d<   |j                  |       ^ |j                  |d   |       | 	 |j                  |       y# |j                  |       w xY w)a  
        Lint a notebook document.

        This is a bit more complicated than linting a text document, because we need to
        send the entire notebook document to the pylsp_lint hook, but we need to send
        the diagnostics back to the client on a per-cell basis.
        r   r   r   r   )r   
line_startline_endsource
rP  TrH  r  r'   lineendrT  rS  r   N)rj   uuiduuid4r   get_cell_document
line_countrU  appendput_documentr   r   rQ  rm_document)r!   r  r   
random_uri	cell_listoffsettotal_sourcecellcell_uricell_document	num_linesr!  document_diagnosticscell_diagnostics
diagnostic
start_lineend_lines                    r#   rL  z'PythonLSPServer._lint_notebook_document  s    &
 +-	%++ 	 DJ'H%77AM%00I  $"Y.2'..	D T"{,33}';'; ;;iF'	 * 	z<8	.#*

<d
C$  " M#% "6 
8J!+G!4W!=f!EJ)'259&AH!D$444CU8U "T,%77 w'08 :BDDV9VJw'.v6$++J7
8 --d5k;KLM  !!*-I!!*-s   ;BE* *E=c                 >    t        | j                  d|||            S )Npylsp_references)r  exclude_declarationr  )r!   r   r  ro  s       r#   
referenceszPythonLSPServer.references  s,    JJ"!$7	  
 	
r$   c                 ,    | j                  d|||      S )Npylsp_rename)r  new_namer	  )r!   r   r  rs  s       r#   renamezPythonLSPServer.rename  s    zz.'HxzXXr$   c                 *    | j                  d||      S )Npylsp_signature_helpr'  r	  r(  s      r#   signature_helpzPythonLSPServer.signature_help  s    zz0'HzMMr$   c                 8    t        | j                  d|            S )Npylsp_folding_ranger  r  s     r#   foldingzPythonLSPServer.folding  s    tzz"7ABBr$   c                 $    | j                  |      S r   )r$  )r!   completionItems     r#   m_completion_item__resolvez*PythonLSPServer.m_completion_item__resolve  s    ++N;;r$   c           
      J   | j                  |d         }|j                  |d   |d   |d   |j                  d      |j                  d             |xs g D ]3  }|j                  |d   |d   |d   |d   |j                  d      	       5 | j	                  |d   d
       y )Nr   notebookTyper   r   metadata)r   r   r  
languageIdtextr   TrH  )r   put_notebook_documentr   put_cell_documentrN  r!   notebookDocumentcellTextDocumentsr   r   rd  s         r#   m_notebook_document__did_openz-PythonLSPServer.m_notebook_document__did_open  s     001A%1HI	''U#^,"7+$((3%))*5 	( 	
 &+ 	D''U '\"V+ ( 	 			"5)D	9r$   c                     | j                  |d         }|xs g D ]+  }|j                  |d   g        |j                  |d          - |j                  |d          y Nr   r   rQ  r_  r  s         r#   m_notebook_document__did_closez.PythonLSPServer.m_notebook_document__did_close/  sj     001A%1HI	%+ 	/D))$u+r:!!$u+.	/ 	.u56r$   c           
         | j                  |d         }|j                  d      r$|j                  |d   |j                  d             |j                  d      }|r|j                  d      }|r|d   }|d   }|d   }	|	dk(  rT|d	   D ]2  }
|j                  |
d   |d   |
d
   |
d   |
j                  d             4 |j	                  |d   |d   |       nI|d   D ]+  }
|j                  |
d          |j                  |
d   g        - |j                  |d   ||	       |j                  d      }|r|D ]  } |j                  d      }|r'|D ]"  }|d   d   }|j                  ||d   d          $ | j                  |d   d       y)a#  
        Changes to the notebook document.

        This could be one of the following:
        1. Notebook metadata changed
        2. Cell(s) added
        3. Cell(s) deleted
        4. Cell(s) data changed
            4.1 Cell metadata changed
            4.2 Cell source changed
        r   r  r   	structurearrayr'   deleteCountr   didOpenr  r  r   didCloser!  textContentr   changesTrH  N)
r   r   update_notebook_metadatar  add_notebook_cellsr_  rQ  remove_notebook_cellsupdate_documentrN  )r!   r  r   r   r   r   r  notebook_cell_array_changer'   cell_delete_countrf  r!  rd  text_contentre  s                  r#   m_notebook_document__did_changez/PythonLSPServer.m_notebook_document__did_change8  s    001A%1HI	::j!.. 'J)? 

7#		+.I-6w-?*27;$>}$M!$) *39)= !33)%0,U3),7)&1)--i8 00(/27; *3:)> P!--mE.BC!55mE6JBOP 33(/8I 99V$D  D !99]3L( LD#J/6H --hY8JK	L
 			"5)D	9r$   c                 ~    | j                  |d         }|j                  |d   g        |j                  |d          y r  r  r!   textDocumentr   r   s       r#   m_text_document__did_closez*PythonLSPServer.m_text_document__did_close  s?    00e1DE	%%l5&92>l512r$   c                     | j                  |d         }|j                  |d   |d   |j                  d             | j                  d|d          | j	                  |d   d       y )Nr   r  r   r  pylsp_document_did_openTrH  )r   r^  r   r   rN  r  s       r#   m_text_document__did_openz)PythonLSPServer.m_text_document__did_open  ss    00e1DE	  $$Y/ 	 	

 	

,l5.AB		,u%	5r$   c                     | j                  |d         }|D ](  }|j                  |d   ||j                  d             * | j                  |d   d       y )Nr   r   r  FrH  )r   r  r   rN  )r!   contentChangesr  r   r   r   s         r#   m_text_document__did_changez+PythonLSPServer.m_text_document__did_change  si     00e1DE	$ 	F%%U#V\5E5Ei5P & 	 			,u%	6r$   c                 X    | j                  |d   d       | j                  |d          y )Nr   TrH  )rN  r/  r!   r  r   s      r#   m_text_document__did_savez)PythonLSPServer.m_text_document__did_save  s*    		,u%	5|E23r$   c                 .    | j                  |d   ||      S r  )r  )r!   r  r  r  r   s        r#   m_text_document__code_actionz,PythonLSPServer.m_text_document__code_action         e!4eWEEr$   c                 *    | j                  |d         S r  )r  r  s      r#   m_text_document__code_lensz*PythonLSPServer.m_text_document__code_lens  s    ~~l5122r$   c                 D   | j                  |j                        }|j                  |j                        }|t        d      |j	                         }dj                  d |j                         D              }|j                  |      5 }||dxx   ||j                     d   z  cc<   | j                  ||      }	|	j                  dg       D ]9  }
|
j                  di       j                  d      |k(  s(|j                  |
d   d<   ; |	cd d d        S # 1 sw Y   y xY w)	NInvalid notebook documentrV  c              3   &   K   | ]	  }|d      ywrU  Nr   .0r!  s     r#   	<genexpr>z=PythonLSPServer._cell_document__completion.<locals>.<genexpr>        ODh O   rW  rS  r  r!  r   )r   r  r  rI   	cell_datajoinr   temp_documentr   r  r   )r!   cellDocumentr  r   r   r  r  rc  temp_urir  r   s              r#   _cell_document__completionz*PythonLSPServer._cell_document__completion  s   001J1JK	$778Q8QR#899$..0	 yy OI<L<L<N OO$$\2 	h# Il.>.>$?$MM **8X>K $4 ?88FB'++I6(B.:.>.>DL+? 	 	 	s   A+D7DDc                     | j                  |d         }|j                  |d         }t        |t              r | j                  ||fi |S | j                  |d   |      S r  )r   r   r+   r   r  r  r!   r  r  r   r   r   s         r#   m_text_document__completionz+PythonLSPServer.m_text_document__completion  h    00e1DE	)),u*=>h%24228XQQQU 3X>>r$   c                    | j                  |j                        }|j                  |j                        }|t        d      |j	                         }dj                  d |j                         D              }|j                  |      5 }||dxx   ||j                     d   z  cc<   | j                  ||      }	|	D ]s  }
|
d   |k(  s|j                         D ]U  \  }}|d   |
d   d   d   cxk  r	|d	   k  s!n $||
d<   |
d   d   dxx   |d   z  cc<   |
d   d
   dxx   |d   z  cc<    s u |	cd d d        S # 1 sw Y   y xY w)Nr  rV  c              3   &   K   | ]	  }|d      ywr  r   r  s     r#   r  z=PythonLSPServer._cell_document__definition.<locals>.<genexpr>  r  r  rW  rS  r   r  r'   rT  rX  )r   r  r  rI   r  r  r   r  r   r)  r  )r!   r  r  r   r   r  r  rc  r  r)  
definitionre  r!  s                r#   _cell_document__definitionz*PythonLSPServer._cell_document__definition  s   001J1JK	$778Q8QR#899$..0	 yy OI<L<L<N OO$$\2 	h# Il.>.>$?$MM **8X>K * "
e$0*3//*; 	"$ .)'27;FC0#J/0 19Ju-&w/8@DDVV@&w/6v>$|BTT>!	"" -	 	 	s   ?E 0E <:E  E	c                     | j                  |d         }|j                  |d         }t        |t              r | j                  ||fi |S | j                  |d   |      S r  )r   r   r+   r   r  r)  r  s         r#   m_text_document__definitionz+PythonLSPServer.m_text_document__definition  r  r$   c                 ,    | j                  |d   |      S r  )rA  r!   r  r  r   s       r#   #m_text_document__document_highlightz3PythonLSPServer.m_text_document__document_highlight  s     ~~l518<<r$   c                 ,    | j                  |d   |      S r  )rE  r  s       r#   m_text_document__hoverz&PythonLSPServer.m_text_document__hover  s    zz,u-x88r$   c                 *    | j                  |d         S r  )r,  r  s      r#    m_text_document__document_symbolz0PythonLSPServer.m_text_document__document_symbol  s    $$\%%899r$   c                 ,    | j                  |d   |      S r  )r;  )r!   r  r9  r   s       r#   m_text_document__formattingz+PythonLSPServer.m_text_document__formatting  s    ##L$7AAr$   c                 .    | j                  |d   ||      S r  )rt  )r!   r  r  newNamer   s        r#   m_text_document__renamez'PythonLSPServer.m_text_document__rename  s     {{<.'BBr$   c                 *    | j                  |d         S r  )rz  r  s      r#   m_text_document__folding_rangez.PythonLSPServer.m_text_document__folding_range  s    ||L/00r$   c                 .    | j                  |d   ||      S r  )r>  )r!   r  r  r9  r   s        r#   !m_text_document__range_formattingz1PythonLSPServer.m_text_document__range_formatting	  r  r$   c                 :    |d    }| j                  |d   ||      S )NincludeDeclarationr   )rp  )r!   r  r  r  r   ro  s         r#   m_text_document__referencesz+PythonLSPServer.m_text_document__references  s,     #**>"??|E2H>QRRr$   c                 ,    | j                  |d   |      S r  )rw  r  s       r#   m_text_document__signature_helpz/PythonLSPServer.m_text_document__signature_help  s     ""<#6AAr$   c                 D   | j                   /| j                   j                  |xs i j                  di              | j                  j	                         D ]H  }|j                  |       | j                  d       |j                  D ]  }| j                  |d        J y )Nr   %pylsp_workspace_configuration_changedFrH  )	r   r   r   r   r   update_configr   rJ  rN  )r!   settingsr   r   s       r#   %m_workspace__did_change_configurationz5PythonLSPServer.m_workspace__did_change_configuration  s    ;;"KKB33GR@A//1 	3I##H-JJ>?$.. 3		'E	23	3r$   c                     |y |j                  dg       }|j                  dg       }|D ](  }d|v s|d   } j                  j                  |d        * |D ]  }d|v s|d   }t        j                  | j                  j
                   j                  j                   j                  j                        }	|	j                   j                  j                         t        | j                  |	       j                  |<    t         fd|D              }
t        |      dkD  xr d|d   v }|
r9|r7|d   d   }| _         j                  |   }|j                   _        | _        nk|
ri j                  r]t"        j%                  d       t'         j                        }|d   } j                  |   }| _        |j                   _        | _        t)         j                   j*                  j-                               }|D ]G  } j                   j*                  j                  |      } j/                  |      }||j*                  |<   I y )Naddedremovedr   c              3   B   K   | ]  }|d    j                   k(    yw)r   N)r   )r  removed_infor!   s     r#   r  zLPythonLSPServer.m_workspace__did_change_workspace_folders.<locals>.<genexpr>;  s$      %
5AL4==0%
s   r   zRoot workspace deleted!)r   r   r   r   r   r   r   r   r   r   r   r   anylenr   _configr   r;   r<   sortedlist_docskeysr   )r!   eventr   r  r  r  removed_uri
added_info	added_urir  root_workspace_removedworkspace_addednew_root_workspaceavailable_workspacesfirst_workspacedoc_urisr   r   new_workspaces   `                  r#   )m_workspace__did_change_workspace_foldersz9PythonLSPServer.m_workspace__did_change_workspace_folders"  s,   =		'2&))Ir*# 	7L$*51##K6	7
   	J
"&u-	#)==KK**KK++KK--	$  !''(=(=>-6t~~/?.	*	 "% %
EL%
 "
 e*q.>UeAh->!oaI%DM!%!;,44DK/DN# 		34'-doo'>$"6q"9%)___%E" /088!3 ,,1134 	+C..&&**3/C 88=M'*M$	+r$   c                    t               }d}|xs g D ]J  }|d   j                  t              r|j                  |d          0|d   j                  t              sId}L |r%| j
                  j                  j                          n|sy | j                  j                         D ]+  }|j                  D ]  }||vs| j                  |d        - y )NFr   TrH  )setendswithPYTHON_FILE_EXTENSIONSaddCONFIG_FILEsr   r  cache_clearr   r   rJ  rN  )r!   r  r   changed_py_filesconfig_changeddr   r   s           r#   %m_workspace__did_change_watched_filesz5PythonLSPServer.m_workspace__did_change_watched_filesY  s    5B 	&Ax  !78 $$QuX.5""<0!%		& KK  ,,.!//1 	7I$.. 7"22IIgI67	7r$   c                 &    | j                  ||      S r   )r5  r4  s      r#   m_workspace__execute_commandz,PythonLSPServer.m_workspace__execute_commandn  s    ##GY77r$   )FNr   )NNNNN)NN)NNN)Dr1   r2   r3   r4   r   r'   rg   r   r   r   r   r   r   r   r  r
  rj   r   r  r  r  r$  r)  r,  r/  r5  r;  r>  rA  rE  r   debounceLINT_DEBOUNCE_SrN  rK  rL  rp  rt  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r5   r6   s   @r#   rH   rH      s   
 <@!QU!FC(
&

0B	
'#V "K
Z(
C 
 
t 

?F
TF>YUW
Y V___y9E :E

@.D
YNC< 8<:, 8<7 -1J:X3
6 1574
 6:F
30? D? +/=
9:B 9=C
1 6:F 9=S +/B
35+n7*8r$   rH   c                 @    | D cg c]  }|D ]  }|  c}}S c c}}w r   r   )list_of_listslstr   s      r#   r   r   r  s"    ):Sc:dD:D:::s   c                 j    | D ci c]  }|j                         D ]  \  }}||
  c}}}S c c}}}w r   )r  )list_of_dicts
dictionarykvs       r#   r   r   v  s6    #0PPZZ=M=M=OPTQAqDPAPPPs   ".)0loggingr)   rK   r=   rY  	functoolsr   typingr   r   r   ujsonrc   pylsp_jsonrpc.dispatchersr   pylsp_jsonrpc.endpointr   pylsp_jsonrpc.streamsr	   r
   r   r   r   r   _versionr   r   r   r   r   r   r   	getLoggerr1   r;   r	  r   r   r  r   StreamRequestHandlerr   rW   rY   r   rH   r   r   r   r$   r#   <module>r     s     	     " "  6 + J   !  : :g!  " ( EL== ,#L6"rR8& R8j;Qr$   