a
    ø£Be|
  ã                   @   sX   d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd	„ Zd
d„ ZdS )zI add language server support to the running jupyter notebook application
é    N)ÚPathé   )Úadd_handlers)ÚLanguageServerManager)Únormalized_uric              	   Ã   sÀ   ddl }ddlm} | j}|j ¡ �&}| j ||j¡I dH  W d  ƒ n1 sP0    Y  dd„ |j	 
¡ D ƒ}t|ƒr�| j d|¡ ||d� n| j d	¡ | j d
 tj|j	ddd�¡¡ dS )zPerform lazy initialization.r   Nr   )Úsetup_shadow_filesystemc                 S   s    g | ]\}}|  d d¡r|‘qS )Zrequires_documents_on_diskT)Úget)Ú.0Z	server_idÚserver© r   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_lsp/serverextension.pyÚ
<listcomp>   s   þzinitialize.<locals>.<listcomp>z:[lsp] Servers that requested virtual documents on disk: %s)Úvirtual_documents_urizZ[lsp] None of the installed servers require virtual documents disabling shadow filesystem.z:[lsp] The following Language Servers will be available: {}é   T)ÚindentÚ	sort_keys)Úconcurrent.futuresZvirtual_documents_shadowr   Úlanguage_server_managerÚfuturesÚThreadPoolExecutorÚio_loopÚrun_in_executorÚ
initializeZlanguage_serversÚitemsÚanyÚlogÚdebugÚformatÚjsonÚdumps)Únbappr   Ú
concurrentr   ÚmanagerÚpoolZservers_requiring_disk_accessr   r   r   r      s,    4þþÿÿÿr   c                 C   sÀ   | j t t¡d� t| d� }| _| j}| jj di ¡}d}d}t	|dƒr†t
|jƒ}| j d|¡ t
t|jƒ|j ƒ}| j d|¡ n| j d|¡ |j||d	� t| ƒ | j d
t| |¡ dS )z/create a LanguageServerManager and add handlers)r   )ÚparentZpage_config_dataÚ Úroot_dirz[lsp] rootUri will be %sz$[lsp] virtualDocumentsUri will be %szA[lsp] %s did not appear to have a root_dir, could not set rootUri)ZrootUriZvirtualDocumentsUrir   N)Z
add_traitsÚ	traitletsÚInstancer   r   Zcontents_managerZweb_appÚsettingsÚ
setdefaultÚhasattrr   r&   r   r   r   Zvirtual_documents_dirÚwarnÚupdater   r   Ú
call_laterr   )r    r"   ÚcontentsZpage_configZroot_urir   r   r   r   Úload_jupyter_server_extension1   s(    

ÿþr0   )Ú__doc__r   Úpathlibr   r'   Úhandlersr   r"   r   Úpathsr   r   r0   r   r   r   r   Ú<module>   s   $