
    ue                         d dl Z d dlmZmZ d dlmZmZmZ  e j                  e	      Z
ed        Zd Zed        Zed        Zd Zd	 Zy)
    N)code_assistsorted_proposals)_utilshookimpllspc                      dddddiiS )Npluginsrope_completionF)enabledeager r       ?/usr/lib/python3/dist-packages/pylsp/plugins/rope_completion.pypylsp_settingsr      s     )uu+MNOOr   c                    	 t        j                  |j                         |      }dj                  |j                  xs d|j                        | d<   || d<   | S # t        $ r"}t        j                  d|       d}Y d }~Zd }~ww xY w)N)markup_kindz%Failed to resolve Rope completion: %s z{0} {1}detaildocumentation)	r   format_docstringget_doc	Exceptionlogdebugformatscopename)
completiondatar   doces        r   _resolve_completionr"      s{    %%dlln+N %++DJJ,<"diiHJx"%J  		91=s   %A 	B$BBc                    | j                  d|j                        }|j                  dd      }|j                  |d   t	        |d   dz
  d      d	      }|d
k(  ry |j                  |      }| j                  |j                        j                  di       }|j                  |      }	|j                  |      }
| j                  j                  di       j                  di       }|j                  di       }|j                  ddg      }t        j                  |      }	 t        |	|j                  ||
d      }t#        |      }g }|D ]Q  }|j$                  t'        |      t)        |      d|j*                  id}|rt-        |||      }|j/                  |       S t1        ||      D ci c]  \  }}|d   ||f c}}|j2                  d<   |}|xs d S # t        $ r"}t        j!                  d|       g cY d }~S d }~ww xY wc c}}w )Nr
   )document_pathr   Fline	character   r   )r%   r&   importropetextDocumentr   completionItemdocumentationFormatmarkdown   )maxfixesz"Failed to run Rope code assist: %sdoc_uri)labelkindsortTextr   r1   LAST_ROPE_COMPLETIONS)plugin_settingspathgetword_at_positionmaxoffset_at_positionsettings_rope_project_builder_rope_resourcecapabilitiesr   choose_markup_kindr   sourcer   r   r   r   r   _kind
_sort_texturir"   appendzipshared_data)config	workspacedocumentpositionr;   resolve_eagerlywordoffsetrope_configrope_projectdocument_ropecompletion_capabilitiesitem_capabilitiessupported_markup_kindspreferred_markup_kinddefinitionsr!   new_definitionsditemr   r   s                         r   pylsp_completionsrY      s,   %%&7x}}%UHll7E2O $$ V$Xk2Q6:		
D x((2F///>BB62NK22;?L++K8M$1155nbIMMb 0334DbI.223H:,W"556LM!(//6=1
 #;/KO 	%VV!H"1-	
 &tQ0EFDt$	% !$O[ A5 J 	7j$//5H01 "K$5  		6:	$5s$   #G /H	H#H :H Hc                 <   |j                   d   j                  |d         }| j                  j                  di       j                  di       }|j                  di       }|j                  ddg      }t        j                  |      }|r|\  }}	t        ||	|      S |S )z>Resolve formatted completion for given non-resolved completionr4   r1   r*   r   r+   r,   r-   )rF   r7   r>   r   r?   r"   )
rG   completion_itemrI   rF   rQ   rR   rS   rT   r   r   s
             r   pylsp_completion_item_resolver\   \   s     &&'>?CC K %1155nbIMMb 0334DbI.223H:,W"556LM&
D":t5JKKr   c                     | j                   j                  d      rd| j                   z   S | j                  dk(  rd| j                   z   S d| j                   z   S )z_Ensure builtins appear at the bottom.
    Description is of format <type>: <module>.<item>
    _zbuiltinya)r   
startswithr   )
definitions    r   rB   rB   p   sS     !!#&Z__$$9$Z__$$   r   c                 b   i dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  d	t         j                  j                  d
t         j                  j
                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  dt         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  d}|j                  | j                        S )zReturn the LSP typenonetypetupledict
dictionaryfunctionlambda	generatorclassinstancemethodr`   builtinfunctionmodulefilexrangeslice)	tracebackframebuffer	dictproxyfuncdefpropertyr(   keywordconstantvariablevalueparam	statement)r   CompletionItemKindValueClassFunction	ReferenceMethodModuleFilePropertyKeywordVariabler7   rg   )rW   MAPs     r   rA   rA   ~   s|   &&,,&&,, 	''-- 	&&,,	
 	c,,22 	C**33 	#((11 	S++44 	''-- 	C**44 	#((// 	3))// 	311:: 	#((// 	&&++  	#((..!" 	''--#$ ++11''--((..++11))22**33((//))11**33**33''--''00++33=CB 77166?r   )loggingrope.contrib.codeassistr   r   pylspr   r   r   	getLogger__name__r   r   r"   rY   r\   rB   rA   r   r   r   <module>r      ss     A ' 'g! 
P 
P
 
: 
:z 
 
&!#r   