
    ue)                        d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	  e j                  e      Zej                  j                  ej                  j                  ej                  j                  ej                  j                   ej                  j"                  ej                  j$                  ej                  j&                  ej                  j(                  ej                  j*                  ej                  j$                  d
ZdZdZed        Zed        Zd	 Zd
 ZdefdZ	 	 	 	 ddefdZddZ ddZ!d Z"d Z#y)    N)_utilshookimpllsp)LABEL_RESOLVERSNIPPET_RESOLVER)
module	namespaceclassinstancefunctionparampathkeywordproperty	statement)import_nameimport_from)
error_nodec                 N   | j                  d|j                        }|j                  dd      }t        j                  ||      }|j                  dd      |d<    |j                  d      j                  di |}|sy| j                  j                  d	i       j                  d
i       }|j                  di       }|j                  d      }	|j                  ddg      }
t        j                  |
      }|j                  d      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }||t        _
        |t        _
        |	xr |xr t        ||      }|	xr |xr t        ||      }|	xr |xr t        ||      }t        |      D cg c])  \  }}t        |||j                  dv r|nd|||k  |	      + }}}|rrt        |      D ]d  \  }}|j                  dk(  st        ||d|||k  |	      }t         j"                  j$                  |d<   |dxx   dz  cc<   |j'                  |       f |rrt        |      D ]d  \  }}|j                  dk(  st        ||d|||k  |	      }t         j"                  j$                  |d<   |dxx   dz  cc<   |j'                  |       f |D ]  }d|j(                  i|d<    t+        ||      D ci c]  \  }}|d   ||f c}}|j,                  d<   |xs dS c c}}w c c}}w ) z3Get formatted completions for current code positionjedi_completion)document_patheagerFfuzzyT)use_document_pathNtextDocument
completioncompletionItemsnippetSupportdocumentationFormatmarkdowninclude_paramsinclude_class_objectsinclude_function_objectsresolve_at_most   	cache_for)r
   r   )markup_kindr!   resolveresolve_label_or_snippetsnippet_supportr
   kindlabelz objectr   doc_uridataLAST_JEDI_COMPLETIONS )plugin_settingsr   getr   position_to_jedi_linecolumnjedi_scriptcompletecapabilitieschoose_markup_kindr   cached_modulesr   use_snippets	enumerate_format_completiontyper   CompletionItemKindTypeParameterappendurizipshared_data)configdocumentpositionsettingsresolve_eagerlycode_positioncompletionscompletion_capabilitiesitem_capabilitiesr*   supported_markup_kindspreferred_markup_kindshould_include_paramsshould_include_class_objectsshould_include_function_objectsmax_to_resolvemodules_to_cache_forr!   r"   r#   icready_completionscompletion_dictr   r.   s                             ?/usr/lib/python3/dist-packages/pylsp/plugins/jedi_completion.pypylsp_completionsrX   &   s    %%&7x}}%UHll7E2O66xJM%\\'59M'G(&&&>GGX-XK$1155nbIMMb 0334DbI'++,<=O.223H:,W"556LM$LL)9:#+<<0G#O &.ll3Mu&U#\\"3R8N#<<T:'(<%*>' 	V1Vl8X6V  	 	-(	-8,  	 	-+	-8,  k*
 Aq 	--.VV7L-L>RW#&'.&8+	

 
 k* 	:DAqvv "4 5#(+./..@$3# +.*@*@*N*N'(I5(!((9	:  k* 	:DAqvv#"4 5#(+./..@$3# +.*@*@*N*N'(I5(!((9	: - <#,hll";< !$$5{ C5 J 	7j$//5H01 $$k
^5s   2.L2L!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 completionr/   r,   r   r   r   r   r    )r'   )rB   r2   r6   r   r7   _resolve_completion)
rC   completion_itemrD   rB   rJ   rK   rL   rM   r   r.   s
             rW   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":tAVWW    c                     	 | t         j                         D cg c]  }|j                   c}v S c c}w # t        $ r Y yw xY w)z
    Determine if a class name is an instance of an Exception.

    This returns `False` if the name given corresponds with a instance of
    the 'Exception' class, `True` otherwise
    F)	Exception__subclasses____name__AttributeError)nameclss     rW   is_exception_classre      sA    	0H0H0JKKKKK  s   5 05 5 	A Ac                    |d   }| j                   j                  d|      }||   d|d    g}|dz  }d}|dkD  r||   }|j                         j                  d      s>|j                         j                  d	      s|j                         j                  d
      r9|j	                  d|       |dz  }|j                         j                  d	      rd}nn|dkD  rd	|d   j                         v rd}dj                  |      j                  dd      d   j                         |z   }t        j                  |      }|j                  d   j                  }	|	t        vxr |	t        v xr d|v  S )z
    Determine if it's necessary to return snippets in code completions.

    This returns `False` if a completion is being requested on an import
    statement, `True` otherwise.
    line
N	character    \(,r   );)maxsplitimport)sourcesplitrstripendswithinsertstripjoinrsplitparsoparsechildrenr<   _IMPORTS_ERRORS)
rD   rE   rg   lines	act_lineslast_characteract_linecodetokens	expr_types
             rW   r9   r9      sm    FDOO!!$-Et4x456IAIDN
);OO&&t, ))#. ))#.Q)AID ))#. "% )  im!!##99Y&&sQ&7;AACnTD[[F"''IH$Xi7.B.WxSWGW)XXr]   r'   c                     t        |      | d<   	 t        j                  |j                  d      |j	                         D cg c]  }|j                          c}|      }|| d<   | S c c}w # t        $ r d}Y w xY w)NdetailT)raw)
signaturesr'   rk   documentation)_detailr   format_docstring	docstringget_signatures	to_stringr_   )r   dr'   	signaturedocss        rW   rZ   rZ      s    "1:Jx&&KKDK!?@?O?O?QR)	++-R#
 #'J S  s#   2A. A)
	A. )A. .A<;A<c                 b   t        | |      t        j                  | j                        t	        |       | j
                  d}|rt        || |      }| j                  dk(  rt        j                  j                  | j
                        }| j
                  j                  t        j                        rt        j
                  dk(  r|dz   }n|dz   }|r$|j                  dd      }|j                  dd      }||d<   |r2t        | j
                        st        | |      }|j                  |       |S )	N)r,   r+   sortText
insertTextr   ntrm   /z\\z\/r   )_label	_TYPE_MAPr2   r<   
_sort_textrc   rZ   osr   normpathrw   sepreplacere   _snippetupdate)	r   r'   r!   r(   r)   r*   r   r   snippets	            rW   r;   r;      s     34aff%qMff	J (QD
 	vvww' 66??266"ww$d{cz <<f-D<<U+D#'
< 08167'"r]   c                 h    |s| j                   S t        j                  |       }|r|S | j                   S N)rc   r   get_or_create)
definitionr(   sigs      rW   r   r     s1    

&
&z
2C

??r]   c                 8    |si S t        j                  |       }|S r   )r   r   )r   r(   r   s      rW   r   r     s    	,,Z8GNr]   c                 ~    	 | j                         j                  xs dS # t        $ r | j                  xs dcY S w xY w)Nrk   )parent	full_namerb   )r   s    rW   r   r     sA    *  ",,22 *##)r)*s     <<c                 v    | j                   j                  d      rdnd}|j                  | j                         S )z_Ensure builtins appear at the bottom.
    Description is of format <type>: <module>.<item>
    _zz{}za{})rc   
startswithformat)r   prefixs     rW   r   r   $  s/     !oo005U5F==))r]   )TFFF)F)$loggingr   r|   pylspr   r   r   pylsp.plugins._resolversr   r   	getLoggerra   logr=   ModuleClass	ReferenceFunctionVariableFileKeywordPropertyr   r   r   rX   r\   re   r9   strrZ   r;   r   r   r   r   r0   r]   rW   <module>r      sK    	  ' ' Eg! $$++''..##))&&00&&//##,,""''%%--&&//''00	 *  
a% 
a%H 
 
&!YHC " "**Z**r]   