
    8@d                         d dl Z d dlZd dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZ  e j        e          Ze	d             Ze	d             ZddZd	 Zd
 ZddZdS )    N)file_resourcesstyle)
FormatCode)hookimpl)get_eol_charsc                     t                               d|           |                     d          5  t          ||          cd d d            S # 1 swxY w Y   d S )Nz Formatting document %s with yapfzformat: yapf)options)loginforeport_progress_format)	workspacedocumentr	   s      9lib/python3.11/site-packages/pylsp/plugins/yapf_format.pypylsp_format_documentr      s    HH/:::		"	">	2	2 2 2x1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   AAAc                     t                               d| |           d|d         d<   |d         dxx         dz  cc<   d|d         d<   |d         d         dz   |d         d         dz   fg}t          | ||          S )	Nz,Formatting document %s in range %s with yapfr   start	characterendline   )linesr	   )r
   r   r   )r   ranger	   r   s       r   pylsp_format_ranger      s    HH;XuMMM"#E'N;	%LA !E%L GnV$q(%,v*>*BCDE85'::::    c                 ~   t          j        t          j                              }t          j        | |          rg S t          j        t          j                            |                     }||S t          j	        |          }|d         }|d         }|
                    d          0t          t          |
                    d                    d          }|
                    d          |
                    d           }|rd}||d<   ||d<   ||d<   |                                D ]\  }}||vr
|||<   |S )NUSE_TABSINDENT_WIDTHtabSizer   insertSpacesCONTINUATION_INDENT_WIDTH)r   GetExcludePatternsForDirosgetcwd	IsIgnoredGetDefaultStyleForDirpathdirnamer   CreateStyleFromConfiggetmaxintitems)document_pathr	   !exclude_patterns_from_ignore_filestyle_configuse_tabsindent_widthstyle_optionvalues           r   get_style_configr5   ,   sV   (6(OPRPYP[P[(\(\%/PQQ 	 "7
&& L  .|<<LJ'H/L{{9)3w{{95566::{{>"".{{>222 	 L'L#/L 0<L,-&}} + +e|++%*\""r   c                 0   g }d}| j         D ]}|j        r|j        r|j        dz
  }|j        r0|                    |dz   dd|dz   ddd|j        |z   d           R|j        r0|j        dz
  }|                    |dd|dz   ddddd           |}|S )Nr   r   r   r   r   r   r   newText )changesoldnewappendr   )diff	eol_chars
text_editsprev_line_nochangelsp_line_nos         r   diff_to_text_editsrG   ^   s6   
 J L, (' (': '	'&* '	' ":>LLZ #	' !-q 0%& 
 !-q 0%& 	 	 ";2      Z 	' *q.K !,%&  !,a%&       " 'Lr   c                    | j                             |          rd S | j        }t          |          dz
  }|r |d         d         d         d         |k    rd S |                    |dd|dz   ddd|d         |z   d	           d S )
Nr   r7   r   r   r   r   r8   r9   r:   )sourceendswithr   lenr@   )r   rB   rC   r   last_line_numbers        r   ensure_eof_new_linerM      s     	** NE5zzA~ jnW-g6v>BRRR ) 
 )1, 	
 	
 9y(      r   c                    | j         }t          |          }|dv r|                    |d          }nd}t          | j        |          }t          ||| j        d|          \  }}|sg S t          j        |          }t          |          }	|
                                 t          |	|          }
t          | ||
           |
S )N)z

)r.   r	   T)r   filename
print_diffr0   )rA   rB   )r   rB   rC   )rI   r   replacer5   r'   r   rQ   whatthepatchparse_patchnextcloserG   rM   )r   r   r	   rI   rB   r0   diff_txtchangedpatch_generatorrA   rC   s              r   r   r      s    _F f%%IN""	400	#(-QQQL""!  Hg  	".x88O  D#CCCJY:VVVVr   )N)NN)loggingr#   yapf.yapflibr   r   yapf.yapflib.yapf_apir   rT   pylspr   pylsp._utilsr   	getLogger__name__r
   r   r   r5   rG   rM   r    r   r   <module>rc      s    				 . . . . . . . . , , , , , ,           & & & & & &g!! 
2 2 
2 
; ; 
;$/ / / /d5 5 5p  8     r   