MCPcopy Index your code
hub / github.com/ipython/ipython / accept_token

Function accept_token

IPython/terminal/shortcuts/auto_suggest.py:564–603  ·  view source on GitHub ↗

Fill partial autosuggestion by token

(event: KeyPressEvent)

Source from the content-addressed store, hash-verified

562
563
564def accept_token(event: KeyPressEvent):
565 """Fill partial autosuggestion by token"""
566 b = event.current_buffer
567 suggestion = b.suggestion
568
569 if suggestion:
570 prefix = _get_query(b.document)
571 text = prefix + suggestion.text
572
573 tokens: List[Optional[str]] = [None, None, None]
574 substrings = [""]
575 i = 0
576
577 for token in generate_tokens(StringIO(text).readline):
578 if token.type == tokenize.NEWLINE:
579 index = len(text)
580 else:
581 index = text.index(token[1], len(substrings[-1]))
582 substrings.append(text[:index])
583 tokenized_so_far = substrings[-1]
584 if tokenized_so_far.startswith(prefix):
585 if i == 0 and len(tokenized_so_far) > len(prefix):
586 tokens[0] = tokenized_so_far[len(prefix) :]
587 substrings.append(tokenized_so_far)
588 i += 1
589 tokens[i] = token[1]
590 if i == 2:
591 break
592 i += 1
593
594 if tokens[0]:
595 to_insert: str
596 insert_text = substrings[-2]
597 if tokens[1] and len(tokens[1]) == 1:
598 insert_text = substrings[-1]
599 to_insert = insert_text[len(prefix) :]
600 b.insert_text(to_insert)
601 return
602
603 nc.forward_word(event)
604
605
606Provider = Union[AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None]

Callers 2

test_autosuggest_tokenFunction · 0.90

Calls 3

generate_tokensFunction · 0.90
_get_queryFunction · 0.85
indexMethod · 0.80

Tested by 2

test_autosuggest_tokenFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…