
    c                        U d dl 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	Z	d dl
Z
d dlmZ d dlmZ d dlmZ  e j        e          ZdZee         ed<   	 ej        d	k    r ej                    d
z  Zn8dej        v r eej        d                   dz  Zn ej                    dz  dz  Ze*e                                re                    de           n(# e$ r Ze                    de           Y dZ[ndZ[ww xY w ed          d             Z ed          d             Zed             Z ddZ!d Z" ed          de#dedefd            Z$de#dedefdZ%dS )    N)	lru_cache)Path)DictOptional)hookimpl)get_eol_chars)ConfigGLOBAL_CONFIGntz.blackXDG_CONFIG_HOMEblackz.configz$Found black global config file at %sz3Error determining black global config file path: %sT)tryfirstc                 "    t          | |          S Nformat_document)configdocuments     2lib/python3.11/site-packages/pylsp_black/plugin.pypylsp_format_documentr      s    68,,,    c                 |    d|d         d<   |d         dxx         dz  cc<   d|d         d<   t          | ||          S )Nr   start	characterendline   r   )r   r   ranges      r   pylsp_format_ranger   $   sP    "#E'N;	%LA !E%L68U333r   c                  $    ddddddddiddidiS )z4Configuration options that can be set on the client.pluginsTX   F)enabledline_lengthpreviewcache_configr#   )r   yapfautopep8 r)   r   r   pylsp_settingsr*   ,   sC     	!  %	  &"E*	
 	
 r   c                 V   |r?|d         d         }|d         d         }d                     |j        ||                   }n$|j        }dddt          |j                  ddd}t	          |j        |           }	 t          ||          }n# t          j        $ r g cY S w xY w||d	gS )
Nr   r   r    r   )r   r   )r   r   )textr   )r   newText)	joinlinessourcelenload_configpathformat_textr   NothingChanged)client_configr   r   r   r   r-   r   formatted_texts           r   r   r   =   s     	
gv&El6"wwx~eCi011a00//a@@
 

 66F$$v>>>   			 7788s   <B B"!B"c                    t          j        |d         |d         |d         |d                    }	 d}t          |           }||dk    rd}|                     |d          } t          j        | |d	         |
          }|r|                    d|          }|S # t
          t          t          f$ r-}t          	                    d|           t           j
        |d }~ww xY w)Ntarget_versionr$   pyiskip_string_normalization)target_versionsr$   is_pyistring_normalizationF
Tfast)rA   modezError formatting with black: %s)r   FileModer   replaceformat_file_contents
ValueErrorIndentationErrorAssertionErrorloggererrorr6   )r-   r   rB   replace_eols	eol_charsr8   es          r   r5   r5   T   s   >/0=)e}!'(C!DD	  D* !$''	 	1Y$%6 	1L<<	400D 3vf~D
 
 

  	E+33D)DDN 	 	 * * * 	6:::")*s   A'B C2(CCd   filenamer7   returnc           	      P  	 |                     d          }|                    dd          d|                     d          dt                      |                    dd          d}t	          j        | f          }t          |t                    r|d         d	z  }n|d	z  }|                                s`t          <t          
                                r#t          }t                              d
|           nt                              d|           |S 	 t          j        t          |                    }n9# t          j        t"          f$ r  t                              d|           |cY S w xY w|                    di                               di           	d 	                                D             		fd|                                D             }	                    d          r t          d 	d         D                       }nv	                    d          rSt          j        j        t          j        j        t          j        j        t          j        j        t          j        j        h}nt                      }||d<   t                              d||           |S )Nr   r$   r"   Fz.pyir%   )r$   rA   r;   r<   r:   r%   r   zpyproject.tomlzUsing global black config at %szUsing defaults: %rz1Error decoding pyproject.toml, using defaults: %rtoolc                 j    i | ]0\  }}|                     d d                               dd          |1S )z--r,   -_)rD   ).0keyvalues      r   
<dictcomp>z _load_config.<locals>.<dictcomp>   sL       C 	D"%%c3//  r   c                 D    i | ]\  }}|                     ||          S r)   )get)rV   rW   default_valuefile_configs      r   rY   z _load_config.<locals>.<dictcomp>   s=       C 	[__S-00  r   r:   c              3   ^   K   | ](}t           j        |                                         V  )d S r   )r   TargetVersionupper)rV   xs     r   	<genexpr>z_load_config.<locals>.<genexpr>   sC       
 
/0E		*
 
 
 
 
 
r   py36zUsing config from %s: %r)plugin_settingsr[   endswithsetr   find_project_root
isinstancetupleis_filer
   existsrI   infotomlloadstrTomlDecodeErrorOSErrorwarningitemsr_   PY36PY37PY38PY39PY310)
rO   r7   settingsdefaultsrootpyproject_filenamepyproject_tomlr   r:   r]   s
            @r   _load_configr~   }   s   ,,W55H  ||M266  ((%*%%<<	511 H "H;//D $ 5!!W'77!$44%%''  	)=)=)?)? 	!.KK9;MNNNNKK,h777O3'9#:#:;; '*   ?	
 	
 	
  !$$VR0044WbAAK %++--  K
   "*.."2"2  F
 '((  
 
4?@P4Q
 
 
 
 
 
	 	  	$$$$%
 -F
KK*,>GGGMs   !D9 93E/.E/c                     |                     d          }|                    dd          st                              | |          S t          | |          S )Nr   r&   F)rd   r[   r~   __wrapped__)rO   r7   ry   s      r   r3   r3      sT    ,,W55H <<.. A''-@@@-000r   r   )&loggingos	functoolsr   pathlibr   typingr   r   r   rm   pylspr   pylsp._utilsr   pylsp.config.configr	   	getLogger__name__rI   r
   __annotations__namehomeenvironrk   rl   	ExceptionrM   rJ   r   r   r*   r   r5   ro   r~   r3   r)   r   r   <module>r      s    				             ! ! ! ! ! ! ! !         & & & & & & & & & & & &		8	$	$ !%x~ $ $ $K	w$ :!	h.	bj	( :RZ(9:;;gE!	i/'9  K]%9%9%;%; K:MJJJ	  K K K
LLFJJJJJJJJK 
4- - - 
44 4 4 
  
 9 9 9 9.&* &* &*R 3C3 Cv C$ C C C CL1# 1f 1 1 1 1 1 1 1s   AC C>C99C>