+
    ^|i]                        ^ RI t ^ RIt^ RIt^ RIHt ^ RIHtHtHtH	t	H
t
Ht ^ RIHtHt ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIH t  ^ RI!H"t"H#t#H$t$ ^ RI%H&t& ^ RI'H(t( ^RI)H*t* R R lt+ ! R R]"4      t, ! R R]4      t-R R lt.R R lt/R R lt0R R lt1R R lt2R  R! lt3R" R# lt4R$ R% lt5R& R' lt6R( R) lt7R* R+ lt8R, R- lt9R. R/ lt:R0 R1 lt;]]]-R3,          t<R2 R3 lt=R4 R5 lt>R6 R7 lt?R# )8    N)StringIO)ListOptionalUnionTupleClassVarAny)Callable	GeneratorBufferKeyPressEvent)named_commands)AutoSuggestFromHistory
SuggestionDocument)HistoryPromptSession)	ProcessorTransformationTransformationInput)get_ipython)generate_tokens)pass_throughc                $    V ^8  d   QhR\         /# )   documentr   )formats   "I/usr/lib/python3/dist-packages/IPython/terminal/shortcuts/auto_suggest.py__annotate__r#      s     8 8 8    c                 <    V P                   V P                  ,          # N)linescursor_position_row)r    s   &r"   
_get_queryr)      s    >>(6677r$   c                   \   a  ] tR t^!t o RtRtR
V 3R lR lltV 3R lR ltV 3R ltRt	V t
R	# )AppendAutoSuggestionInAnyLinea  
Append the auto suggestion to lines other than the last (appending to the
last line is natively supported by the prompt toolkit).

This has a private `_debug` attribute that can be set to True to display
debug information as virtual suggestion on the end of any line. You can do
so with:

    >>> from IPython.terminal.shortcuts.auto_suggest import AppendAutoSuggestionInAnyLine
    >>> AppendAutoSuggestionInAnyLine._debug = True

Fc                $   < V ^8  d   QhRS[ RR/# )r   stylereturnN)str)r!   __classdict__s   "r"   r#   *AppendAutoSuggestionInAnyLine.__annotate__1   s      c  r$   c                    Wn         R # r&   r-   )selfr-   s   &&r"   __init__&AppendAutoSuggestionInAnyLine.__init__1   s    
r$   c                &   < V ^8  d   QhRS[ RS[/# )r   tir.   )r   r   )r!   r0   s   "r"   r#   r1   4   s      i6 i6': i6~ i6r$   c                  a a SP                   P                  ^,
          pSP                  V8H  pV V3R lpSP                   P                  ^8X  d	   V! R4      # SP                   P                  V8X  d   V'       d	   V! R4      # SP                  SP                   P                  8  d	   V! R4      # SP                  P
                  pVP                  '       d   SP                   P                  '       g	   V! R4      # SP                  SP                   P                  ,
          pVP                  P                  P                  4       p\        V4      ^ 8X  d	   V! R4      # \        P                  R8  d   \        V4      ^8  do   \        P                  R8  dZ   SP                  SP                   P                  8X  d   \        SP                  R.,           R7      # \        SP                  R7      # \        V4      ^8X  dW   SP                  SP                   P                  8X  d2   \        SP                  S P                  V^ ,          3.,           R7      # \        SP                  R7      # V^ 8X  d4   V^ ,          p\        SP                  S P                  V3.,           R7      # V'       Ed<   V\        V4      8  d/   R\        V4      V,
           R	2p\        S P                  V3.4      # \        V4      p	\!        \        V4      4       FS  p
SP#                  W*,
          4      pR
P%                  R V 4       4      P'                  4       pV'       d    MV	^,          p	KU  	  V	'       d   \        S P                  RV	 R23.4      # \        SP#                  V\        V4      ,
          ^,           4      S P(                  '       d   S P                  R3.,           4      # . ,           4      # V\        V4      8  d!   Wv,          p\        S P                  V3.4      # SP                  \        V4      ,
          ^,           p\        SP#                  V4      4      # )a  
 Apply transformation to the line that is currently being edited.

 This is a variation of the original implementation in prompt toolkit
 that allows to not only append suggestions to any line, but also to show
 multi-line suggestions.

 As transformation are applied on a line-by-line basis; we need to trick
 a bit, and elide any line that is after the line we are currently
 editing, until we run out of completions. We cannot shift the existing
 lines

 There are multiple cases to handle:

 The completions ends before the end of the buffer:
     We can resume showing the normal line, and say that some code may
     be hidden.

The completions ends at the end of the buffer
     We can just say that some code may be hidden.

 And separately:

 The completions ends beyond the end of the buffer
     We need to both say that some code may be hidden, and that some
     lines are not shown.

c                    < \        SP                  SP                  SP                  '       d
   R V ,           MR3.,           R7      # )  	fragments)r   r>   r-   _debug)textr4   r8   s   &r"   <lambda>DAppendAutoSuggestionInAnyLine.apply_transformation.<locals>.<lambda>T   s1    Nlltzz3:RT&U%VV
r$   znoop:onelineznoop:last line and cursorznoop:before cursorznoop:not eolznoop: no suggestionsr=   u   … rest of suggestion (z lines) and code hiddenr<   c              3   2   "   T F  q^,          x  K  	  R# 5i)   N ).0ls   & r"   	<genexpr>EAppendAutoSuggestionInAnyLine.apply_transformation.<locals>.<genexpr>   s     .2aqTT2s   u   … z line(s) hiddenzshift-last-line)   r   1   )redzD(Cannot show multiline suggestion; requires prompt_toolkit > 3.0.49))r    
line_countlinenor(   buffer_controlbuffer
suggestionis_cursor_at_the_end_of_liner@   
splitlineslenprompt_toolkitVERSIONr   r>   r-   rangeget_linejoinstripr?   )r4   r8   last_line_numberis_last_linenooprP   deltasuggestionsrQ   n_elidedillelshifts   ff            r"   apply_transformation2AppendAutoSuggestionInAnyLine.apply_transformation4   s   : ;;11A5yy$44
 ;;!!Q&'';;**.>><344 99r{{666,--""))   (P(P(P''		BKK;;;'',,779{q .//!!J.;!#(>(>(K99 ? ??)"$,,#  *BLLAA[!Q&99 ? ??)"$,,4::{1~2N1O"O  "BLL99A:$QJ!BLLTZZ<T;U,UVV<s;''7K8H58P7QQhi
%

J'?&@AA;'H3{+,[[!1!56WW.2..446MH - %

d8*O4T'U&VWW%KK 03{3C Ca GH<@KKK%678Q MOQ 
 S%%$+J!DJJ
#;"<==IIK 0014E!"++e"455r$   c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # )r   r?   )r   bool)r!   r0   s   "r"   r#   r1   !   s      TN" r$   r3   N)zclass:auto-suggestion)__name__
__module____qualname____firstlineno____doc__r?   r5   re   __annotate_func____static_attributes____classdictcell__)r0   s   @r"   r+   r+   !   s.      #F i6 i6'  r$   r+   c                   F  a a ] tR t^t oRtRtR tV 3R ltV3R lR ltV3R lR lt	V3R	 lR
 lt
V3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR lt]R 4       tV3R lR ltV3R lR ltV3R  ltR!tVtV ;t# )"NavigableAutoSuggestFromHistoryz
A subclass of AutoSuggestFromHistory that allow navigation to next/previous
suggestion from history. To do so it remembers the current position, but it
state need to carefully be cleared on the right events.
Nc                    R # )wrongrE   )r4   xs   &&r"   rA   (NavigableAutoSuggestFromHistory.<lambda>   s    gr$   c                j   < \         SV `  4        ^ V n        . V n        RV n        RV n        ^ V n        R# r   N)superr5   
skip_lines_connected_apps_llm_provider_instance_init_llm_provider_request_number)r4   	__class__s   &r"   r5   (NavigableAutoSuggestFromHistory.__init__   s5    !&*#"& r$   c                $   < V ^8  d   QhRS[ RR/# )r   _r.   Nr   )r!   r0   s   "r"   r#   ,NavigableAutoSuggestFromHistory.__annotate__   s       4 r$   c                    ^ V n         R# rx   )rz   )r4   r   s   &&r"   reset_history_position6NavigableAutoSuggestFromHistory.reset_history_position   s	    r$   c                   < V ^8  d   QhRR/# r   r.   NrE   )r!   r0   s   "r"   r#   r      s     J JD Jr$   c                    V P                  4        V P                   F4  pVP                  P                  pVP	                  V P
                  4       K6  	  R # r&   )_cancel_running_llm_taskr{   default_bufferon_text_insertremove_handlerr   )r4   pt_apptext_insert_events   &  r"   
disconnect*NavigableAutoSuggestFromHistory.disconnect   sD    %%'**F & 5 5 D D,,T-H-HI +r$   c                $   < V ^8  d   QhRS[ RR/# )r   r   r.   Nr   )r!   r0   s   "r"   r#   r      s     T Tm T Tr$   c                    V P                   P                  V4       VP                  P                  P	                  V P
                  4       VP                  P                  P	                  V P                  4       R # r&   )r{   appendr   r   add_handlerr   on_cursor_position_changed_dismiss)r4   r   s   &&r"   connect'NavigableAutoSuggestFromHistory.connect   sV    ##F+ 	,,889T9TU88DDT]]Sr$   c                <   < V ^8  d   QhRS[ RS[RS[S[,          /# )r   rP   r    r.   )r   r   r   r   )r!   r0   s   "r"   r#   r      s*      (0	*	r$   c                    \        V4      pVP                  4       '       d;   V P                  W0P                  VP                  4       F  w  rE\        V4      u # 	  R # r&   )r)   rZ   _find_next_matchrz   historyr   )r4   rP   r    r@   rQ   r   s   &&&   r"   get_suggestion.NavigableAutoSuggestFromHistory.get_suggestion   sO     (#::<<!%!6!6oov~~"
 "*--"
 r$   c                   < V ^8  d   QhRR/# r   rE   )r!   r0   s   "r"   r#   r      s     ! !4 !r$   c                4    V P                  4        R Vn        R # r&   )r   rQ   )r4   rP   argskwargss   &&*,r"   r   (NavigableAutoSuggestFromHistory._dismiss   s    %%' r$   c                d   < V ^8  d   QhRS[ RS[RS[RS[RS[S[S[ S[3,          RR3,          /# )r   r@   rz   r   previousr.   N)r/   floatr   rh   r   r   )r!   r0   s   "r"   r#   r      sJ     ' ''%*'5<'HL'	5e$dD0	1'r$   c              #    "   Rp\        \        VP                  4       4      4       F  p\        VP                  4       4       Fr  pV^,          pV'       g	   WR8  d   K  VP	                  V4      '       d,   \        V4      \        V4      8  d   V\        V4      R V3x  V'       g   Kh  WR8  g   Kp    R# 	  K  	  R# 5i)a  
text : str
    Text content to find a match for, the user cursor is most of the
    time at the end of this text.
skip_lines : float
    number of items to skip in the search, this is used to indicate how
    far in the list the user has navigated by pressing up or down.
    The float type is used as the base value is +inf
history : History
    prompt_toolkit History instance to fetch previous entries from.
previous : bool
    Direction of the search, whether we are looking previous match
    (True), or next match (False).

Yields
------
Tuple with:
str:
    current suggestion.
float:
    will actually yield only ints, which is passed back via skip_lines,
    which may be a +inf (float)


N)reversedlistget_stringsrS   
startswithrT   )r4   r@   rz   r   r   line_numberstringlines   &&&&&   r"   _find_match+NavigableAutoSuggestFromHistory._find_match   s     8 tG$7$7$9:;F !2!2!45q K$< ??4((SYT-Bs4y{+[888 9 6 <s   A3B?60B?+B?3B?c                ^   < V ^8  d   QhRS[ RS[RS[RS[S[S[ S[3,          RR3,          /# )r   r@   rz   r   r.   N)r/   r   r   r   r   )r!   r0   s   "r"   r#   r     sH     K KK%*K5<K	5e$dD0	1Kr$   c                *    V P                  WVR R7      # )Fr   )r   r4   r@   rz   r   s   &&&&r"   r   0NavigableAutoSuggestFromHistory._find_next_match  s     'EJJr$   c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   r@   rz   r   )r/   r   r   )r!   r0   s   "r"   r#   r     s"     
 
 
% 
' 
r$   c                N    \        \        V P                  WVR R7      4      4      # )Tr   )r   r   r   r   s   &&&&r"   _find_previous_match4NavigableAutoSuggestFromHistory._find_previous_match  s)    !!$Gd!KL
 	
r$   c                0   < V ^8  d   QhRS[ RS[ RS[RR/# r   query
other_thanr   r.   Nr/   r   )r!   r0   s   "r"   r#   r     s)            w  4  r$   c                    V P                  4        V P                  WP                  V4       F  w  rEW,           V8w  g   K  WPn         R# 	  ^ V n        R# rx   )r   r   rz   r4   r   r   r   rQ   r   s   &&&&  r"   up"NavigableAutoSuggestFromHistory.up  sM    %%''+'<'<??G(
#J !Z/"-(
  DOr$   c                0   < V ^8  d   QhRS[ RS[ RS[RR/# r   r   )r!   r0   s   "r"   r#   r   #  s)      # 3  T r$   c                   V P                  4        V P                  WP                  V4       F  w  rEW,           V8w  g   K  WPn         R# 	  V P                  V\        R 4      V4       F  w  rEW,           V8w  g   K  WPn         R# 	  R# )InfN)r   r   rz   r   r   s   &&&&  r"   down$NavigableAutoSuggestFromHistory.down#  s~    %%''+'@'@??G(
#J !Z/"-(
 ,0+D+DuU|W,'
 %3&1O,r$   c                   < V ^8  d   QhRR/# r   rE   )r!   r0   s   "r"   r#   r   4  s      $ r$   c                
   V P                   eu   V P                   P                  4       '       d
   RV n         R# V P                   P                  4       pV'       d   RV n         V'       g   \        P                  ! R4       R# R# R# )zM
Try to cancel the currently running llm_task if exists, and set it to None.
Nz@LLM task not cancelled, does your provider support cancellation?)	_llm_taskdonecancelwarningswarn)r4   	cancelleds   & r"   r   8NavigableAutoSuggestFromHistory._cancel_running_llm_task4  sc     >>%~~""$$!%--/I!%V  &r$   c                    V P                   f(   V P                  '       d   V P                  4       V n         V P                   # )zLazy-initialized instance of the LLM provider.

Do not use in the constructor, as `_init_llm_provider` can trigger slow side-effects.
)r|   r}   )r4   s   &r"   _llm_provider-NavigableAutoSuggestFromHistory._llm_providerD  s8     &&.43J3J3J*.*A*A*CD'***r$   c                   < V ^8  d   QhRR/# r   rE   )r!   r0   s   "r"   r#   r   N  s        D  r$   c                b  a "    ^ RI pS P                  '       g   \        P                  ! R4       R# Vf   \        P                  ! R4       S P                  4        V 3R lp\        P                  ! V! V4      4      S n        S P                  G Rj  xL
  R#   \         d    Rp Li ; i L5i)z
This will ask the current llm provider a suggestion for the current buffer.

If there is a currently running llm task, it will cancel it.
N5No LLM provider found, cannot trigger LLM completionsz;LLM Completion requires `jupyter_ai_magics` to be installedc                   <"    SP                  V 4      G Rj  xL
  R#  L  \         d+   p\        4       P                  P	                  RT4       h Rp?ii ; i5i)zi
This catches and log any errors, as otherwise this is just
lost in the void of the future running task.
Nzerror %s)_trigger_llm_core	Exceptionr   logerror)rP   er4   s   & r"   error_catcherCNavigableAutoSuggestFromHistory._trigger_llm.<locals>.error_catchera  sI     
,,V444 !!''
A6s0   A"  " A" A%AAA)	jupyter_ai_magicsModuleNotFoundErrorr   r   r   r   asynciocreate_taskr   )r4   rP   r   r   s   f&  r"   _trigger_llm,NavigableAutoSuggestFromHistory._trigger_llmN  s     	%$ !!!MMQR$MMWX%%'		 !,,]6-BCnn/ # 	% $	%. 	s9   B/B B/A8B/B-B/B*'B/)B**B/c                    < V ^8  d   QhRS[ /# r   rP   r   )r!   r0   s   "r"   r#   r   p  s     F Ff Fr$   c                  "    ^ RI Hu Hp V'       g   \	        R4      hV P
                  '       g   \	        R4      hVP                  P                  P                  pV P                  V4      p\        4       P                  P                  RV4       V ;P                  ^,          un        V P                  pVP                  VWAP                  P                   ,           VP                  P"                  RRRRRR7      pV P
                  P%                  V4        Rj  xL
  pV P                  V8w  d    R# \'        WrP(                  4      '       d   \+        VP,                  P.                  4      ^8  d   \	        R	4      h\1        VP,                  P.                  ^ ,          P2                  4      Vn        VP6                  P9                  4        K  \'        WrP:                  4      '       g   K  \1        VP<                  P2                  4      Vn        VP6                  P9                  4        EK    \         d    Rp EL3i ; i EL'ED)R# 5i)
a  
This is the core of the current llm request.

Here we build a compatible `InlineCompletionRequest` and ask the llm
provider to stream it's response back to us iteratively setting it as
the suggestion on the current buffer.

Unlike with JupyterAi, as we do not have multiple cells, the cell id
is always set to `None`.

We set the prefix to the current cell content, but could also insert the
rest of the history or even just the non-fail history.

In the same way, we do not have cell id.

LLM provider may return multiple suggestion stream, but for the time
being we only support one.

Here we make the assumption that the provider will have
stream_inline_completions, I'm not sure it is the case for all
providers.
Nzjupyter-ai is not installedr   z
prefix: %sztext/x-pythonTpython)numberprefixsuffixmimestreampathlanguagecell_idzBTerminal IPython cannot deal with multiple LLM suggestions at once)jupyter_ai.completions.modelscompletionsmodelsr   
ValueErrorr   r   shellhistory_manager_llm_prefixerr   r   debugr~   InlineCompletionRequestr    text_before_cursortext_after_cursorstream_inline_completions
isinstanceInlineCompletionReplyrT   r   itemsr   
insertTextrQ   on_suggestion_setfireInlineCompletionStreamChunkresponse)r4   rP   
jai_modelshmr   request_numberrequestreply_and_chunkss   &&      r"   r   1NavigableAutoSuggestFromHistory._trigger_llm_corep  s    .	>> :;;!!!TUU^^!!11##B'f5!--44!OO>>>??44  5 	
 '+&8&8&R&R'
 	0 	0" ##~5*,L,LMM',,223a7$\  %/$))//2==%! ((--/,.T.TUU$./?/H/H/S/S$T!((--/Y # 	J	6	0 '
$ 	s^   I	H0 IIC'IIII!C	I/AI0I=I IIIIc                   < V ^8  d   Qh/ S[ ;R&   S[S[,          ;R&   S[P                  R,          ;R&   S[R,          ;R&   S[R,          ;R&   S[;R&   # )r   rz   r{   Nr   r}   r|   r   )intr   r   r   Taskr
   r	   )r!   r0   s   "r"   r#   r      sh      O  -((  ||d") " !4'# &  $J&' ( 5) r$   )r{   r}   r|   r   r~   rz   )ri   rj   rk   rl   rm   r   r   r5   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   rn   ro   rp   __classcell__)r   r0   s   @@r"   rr   rr      s      &*I 6M! J JT T ! !' 'RK K

 

   " "   + +   DF Fa  r$   rr   c                $    V ^8  d   QhR\         /# r   eventr   )r!   s   "r"   r#   r#     s     6 6M 6r$   c                  "   ^p\        4       P                  p\        V\        4      '       g   R# V P                  P
                  p\        ^ WP                  ,
          VP                  ,           4      p\        V4       F!  pV P                  P                  RRRR7       K#  	  VP                  V P                  4      G Rj  xL
  R#  L5i)z
Ask the AutoSuggester from history to delegate to ask an LLM for completion

This will first make sure that the current buffer have _MIN_LINES (7)
available lines to insert the LLM completion

Provisional as of 8.32, may change without warnings

N
F)move_cursor
fire_event)r   auto_suggestr   rr   current_bufferr    maxrM   r(   rW   insert_textr   )r  
_MIN_LINESproviderdoclines_to_insertr   s   &     r"   llm_autosuggestionr!    s      J}))Hh ?@@



'
'C!Z..83;R;RRSO?#((5U(S $ 

 4 4
555s   C CC	Cc                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s       r$   c                p   V P                   pVP                  pVP                  VP                  R pVP	                  R4      pV^ ,          P                  4       pVP                  pVe7   VP                  '       d%   VR8X  d   VP                  VP                  4       R# \        P                  ! V 4       R# )z,Apply autosuggestion or jump to end of line.Nr  r<   )
r  r    r@   cursor_positionsplitrZ   rQ   r  ncend_of_line)r  rP   dafter_cursorr'   end_of_current_linerQ   s   &      r"   accept_or_jump_to_endr+    s    !!FA66!++-.Lt$E(..*""JZ___;NRT;T:??+
ur$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s      - r$   c                    V P                   pVP                  pV'       d   VP                  VP                  4       R# \        P
                  ! V 4       R# )zAccept autosuggestionN)r  rQ   r  r@   r&  forward_char)r  rP   rQ   s   &  r"   acceptr/    s9    !!F""J:??+
r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s      = r$   c                ,    V P                   pRVn        R# )zDiscard autosuggestionN)r  rQ   )r  rP   s   & r"   discardr2    s    !!FFr$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s      } r$   c                    V P                   pVP                  pV'       dF   \        P                  ! RVP                  4      pVP                  \        R V 4       R4      4       R# \        P                  ! V 4       R# )z#Fill partial autosuggestion by wordz(\S+\s+)c              3   8   "   T F  q'       g   K  Vx  K  	  R # 5ir&   rE   )rF   ru   s   & r"   rH   accept_word.<locals>.<genexpr>  s      3AqAs   	
r<   N)	r  rQ   rer%  r@   r  nextr&  forward_word)r  rP   rQ   ts   &   r"   accept_wordr;    sV    !!F""JHH[*//24 3A 3R89
r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s     * *M *r$   c                    V P                   pVP                  pV'       d9   VP                  '       d%   VP                  VP                  ^ ,          4       R# R# R# )z(Fill partial autosuggestion by characterN)r  rQ   r@   r  )r  brQ   s   &  r"   accept_characterr?    s=    AJjooo	jooa() &zr$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#      s     . .- .r$   c                    V P                   pVP                  pVP                  pV'       d$   VP                  VP                  4       W!n        R# R# )z.Accept autosuggestion and keep cursor in placeN)r  r$  rQ   r  r@   )r  rP   old_positionrQ   s   &   r"   accept_and_keep_cursorrC     sC    !!F))L""J:??+!- r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#   
  s      } r$   c                H    \        V 4       \        P                  ! V 4       R# )z3Accept autosuggestion and move cursor left in placeN)rC  r&  backward_charr  s   &r"   accept_and_move_cursor_leftrH  
  s    5!Ur$   c                $    V ^8  d   QhR\         /# r   r   )r!   s   "r"   r#   r#     s     ' ' 'r$   c                     V P                   '       d.   V P                   P                  W P                  4      pWn        R # R # r&   )r  r   r    rQ   )rP   rQ   s   & r"   _update_hintrK    s3    ((77P
& r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s     ' '] 'r$   c                \    \         P                  ! V 4       \        V P                  4       R# )z4Resume autosuggestions after deleting last characterN)r&  backward_delete_charrK  r  rG  s   &r"   backspace_and_resume_hintrO    s    E"%%&r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s     ' '- 'r$   c                \    \         P                  ! V 4       \        V P                  4       R# )zResume autosuggestionsN)r   replyrK  r  rG  s   &r"   resume_hintingrS    s     u %%&r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#   $  s     ! !m !r$   c                l    V P                   pVP                  V P                  R7       \        V4       R# )zGo up and update hintcountN)r  auto_upargrK  r  r  s   & r"   up_and_update_hintr[  $  s*    ))N+ r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#   ,  s     ! ! !r$   c                l    V P                   pVP                  V P                  R7       \        V4       R# )zGo down and update hintrV  N)r  	auto_downrY  rK  rZ  s   & r"   down_and_update_hintr_  ,  s*    ))N599- r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#   4  s     ' ' 'r$   c                   V P                   pVP                  pV'       Ed   \        VP                  4      pW2P                  ,           p. ROpR.p^ p\        \        V4      P                  4       F  pVP                  \        P                  8X  d   \        V4      p	M)VP                  V^,          \        VR,          4      4      p	VP                  VRV	 4       VR,          p
V
P                  V4      '       g   K  V^ 8X  dE   \        V
4      \        V4      8  d,   V
\        V4      R V^ &   VP                  V
4       V^,          pV^,          WW&   V^8X  d    MV^,          pK  	  V^ ,          '       dZ   VR,          pV^,          '       d!   \        V^,          4      ^8X  d
   VR,          pV\        V4      R pVP                  V4       R# \         P"                  ! V 4       R# )z$Fill partial autosuggestion by tokenNr<   )NNNr   )r  rQ   r)   r    r@   r   r   readlinetypetokenizeNEWLINErT   indexr   r   r  r&  r9  )r  r>  rQ   r   r@   tokens
substringsra   tokenrg  tokenized_so_farr  	to_inserts   &            r"   accept_tokenrm  4  s   AJzAJJ''&8T
$Xd^%<%<=EzzX---D	

58SB-@Ad6El+)"~**6226c"23c&kA 0V ?F1I%%&67FA!!H	6Q >" !99$R.KayyS^q0(n#CKM2IMM)$OOEr$   c                <    V ^8  d   QhR\         R\        R\        /# )r   rP   r  direction_method)r   rr   r
   )r!   s   "r"   r#   r#   a  s&     ' ''-' 'r$   c                    V P                   pV'       g   R# \        V P                  4      pWCP                  ,           pV! WEV P                  R7       VP                  W P                  4      pW`n         R# )a  
We skip most recent history entry (in either direction) if it equals the
current autosuggestion because if user cycles when auto-suggestion is shown
they most likely want something else than what was suggested (otherwise
they would have accepted the suggestion).
N)r   r   r   )rQ   r)   r    r@   r   r   )rP   r  ro  rQ   r   currentnew_suggestions   &&&    r"   _swap_autosuggestionrs  a  sW     ""Jv'Eoo%G5fnnM,,V__EN&r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#   y  s     
 
- 
r$   c                    \        4       pVP                  p\        V\        4      '       g   R# \	        V P
                  W"P                  R7      # )z%Get next autosuggestion from history.NrP   r  ro  )r   r  r   rr   rs  r  r   r  r   r  s   &  r"   swap_autosuggestion_uprx  y  sA    ME!!Hh ?@@##h r$   c                $    V ^8  d   QhR\         /# r  r   )r!   s   "r"   r#   r#     s      M r$   c                    \        4       pVP                  p\        V\        4      '       g   R# \	        V P
                  VVP                  R7      # )z)Get previous autosuggestion from history.Nrv  )r   r  r   rr   rs  r  r   rw  s   &  r"   swap_autosuggestion_downr{    sE    ME!!Hh ?@@##! r$   )@r7  r   re  ior   typingr   r   r   r   r   r	   collections.abcr
   r   r   rU   prompt_toolkit.bufferr   prompt_toolkit.key_bindingr   #prompt_toolkit.key_binding.bindingsr   r&  prompt_toolkit.auto_suggestr   r   prompt_toolkit.documentr   prompt_toolkit.historyr   prompt_toolkit.shortcutsr    prompt_toolkit.layout.processorsr   r   r   IPython.core.getipythonr   IPython.utils.tokenutilr   filtersr   r)   r+   rr   r!  r+  r/  r2  r;  r?  rC  rH  rK  rO  rS  r[  r_  rm  Providerrs  rx  r{  rE   r$   r"   <module>r     s    	    > > /   ( 4 D J , * 2  0 3 !8|6I |6~V&< Vr6,*.'''!!'T ')H$NO'0
r$   