Show More
@@ -1162,11 +1162,36 b' class Completer(Configurable):' | |||
|
1162 | 1162 | raise |
|
1163 | 1163 | except Exception: |
|
1164 | 1164 | # Silence errors from completion function |
|
1165 | #raise # dbg | |
|
1166 | 1165 | pass |
|
1167 | 1166 | # Build match list to return |
|
1168 | 1167 | n = len(attr) |
|
1169 | return ["%s.%s" % (expr, w) for w in words if w[:n] == attr] | |
|
1168 | ||
|
1169 | # Note: ideally we would just return words here and the prefix | |
|
1170 | # reconciliator would know that we intend to append to rather than | |
|
1171 | # replace the input text; this requires refactoring to return range | |
|
1172 | # which ought to be replaced (as does jedi). | |
|
1173 | tokens = _parse_tokens(expr) | |
|
1174 | rev_tokens = reversed(tokens) | |
|
1175 | skip_over = {tokenize.ENDMARKER, tokenize.NEWLINE} | |
|
1176 | name_turn = True | |
|
1177 | ||
|
1178 | parts = [] | |
|
1179 | for token in rev_tokens: | |
|
1180 | if token.type in skip_over: | |
|
1181 | continue | |
|
1182 | if token.type == tokenize.NAME and name_turn: | |
|
1183 | parts.append(token.string) | |
|
1184 | name_turn = False | |
|
1185 | elif token.type == tokenize.OP and token.string == "." and not name_turn: | |
|
1186 | parts.append(token.string) | |
|
1187 | name_turn = True | |
|
1188 | else: | |
|
1189 | # short-circuit if not empty nor name token | |
|
1190 | break | |
|
1191 | ||
|
1192 | prefix_after_space = "".join(reversed(parts)) | |
|
1193 | ||
|
1194 | return ["%s.%s" % (prefix_after_space, w) for w in words if w[:n] == attr] | |
|
1170 | 1195 | |
|
1171 | 1196 | def _evaluate_expr(self, expr): |
|
1172 | 1197 | obj = not_found |
@@ -543,6 +543,7 b' class TestCompleter(unittest.TestCase):' | |||
|
543 | 543 | """ |
|
544 | 544 | ip = get_ipython() |
|
545 | 545 | ip.ex("a=list(range(5))") |
|
546 | ip.ex("d = {'a b': str}") | |
|
546 | 547 | _, c = ip.complete(".", line="a[0].") |
|
547 | 548 | self.assertFalse(".real" in c, "Shouldn't have completed on a[0]: %s" % c) |
|
548 | 549 | |
@@ -561,14 +562,14 b' class TestCompleter(unittest.TestCase):' | |||
|
561 | 562 | _( |
|
562 | 563 | "a[0].", |
|
563 | 564 | 5, |
|
564 |
" |
|
|
565 | ".real", | |
|
565 | 566 | "Should have completed on a[0].: %s", |
|
566 | 567 | Completion(5, 5, "real"), |
|
567 | 568 | ) |
|
568 | 569 | _( |
|
569 | 570 | "a[0].r", |
|
570 | 571 | 6, |
|
571 |
" |
|
|
572 | ".real", | |
|
572 | 573 | "Should have completed on a[0].r: %s", |
|
573 | 574 | Completion(5, 6, "real"), |
|
574 | 575 | ) |
@@ -576,10 +577,24 b' class TestCompleter(unittest.TestCase):' | |||
|
576 | 577 | _( |
|
577 | 578 | "a[0].from_", |
|
578 | 579 | 10, |
|
579 |
" |
|
|
580 | ".from_bytes", | |
|
580 | 581 | "Should have completed on a[0].from_: %s", |
|
581 | 582 | Completion(5, 10, "from_bytes"), |
|
582 | 583 | ) |
|
584 | _( | |
|
585 | "assert str.star", | |
|
586 | 14, | |
|
587 | "str.startswith", | |
|
588 | "Should have completed on `assert str.star`: %s", | |
|
589 | Completion(11, 14, "startswith"), | |
|
590 | ) | |
|
591 | _( | |
|
592 | "d['a b'].str", | |
|
593 | 12, | |
|
594 | ".strip", | |
|
595 | "Should have completed on `d['a b'].str`: %s", | |
|
596 | Completion(9, 12, "strip"), | |
|
597 | ) | |
|
583 | 598 | |
|
584 | 599 | def test_omit__names(self): |
|
585 | 600 | # also happens to test IPCompleter as a configurable |
General Comments 0
You need to be logged in to leave comments.
Login now