|
43 | 43 | frombpython.lineimportLinePart |
44 | 44 | frombpython._py3compatimportpy3,try_decode |
45 | 45 | frombpython.lazyreimportLazyReCompile |
46 | | -frombpython.simpleevalimportsafe_eval,EvaluationError |
| 46 | +frombpython.simpleevalimport (safe_eval,evaluate_current_expression, |
| 47 | +EvaluationError) |
47 | 48 |
|
48 | 49 | ifnotpy3: |
49 | 50 | fromtypesimportInstanceType,ClassType |
@@ -241,7 +242,7 @@ def matches(self, cursor_offset, line, **kwargs): |
241 | 242 | ifrisNone: |
242 | 243 | returnNone |
243 | 244 |
|
244 | | -iflocals_isNone: |
| 245 | +iflocals_isNone:# TODO add a note about why |
245 | 246 | locals_=__main__.__dict__ |
246 | 247 |
|
247 | 248 | assert'.'inr.word |
@@ -524,6 +525,41 @@ def locate(self, current_offset, line): |
524 | 525 | returnlineparts.current_string_literal_attr(current_offset,line) |
525 | 526 |
|
526 | 527 |
|
| 528 | +classExpressionAttributeCompletion(AttrCompletion): |
| 529 | +# could replace ArrayItemMember completion and attr completion |
| 530 | +# as a more general case |
| 531 | +deflocate(self,current_offset,line): |
| 532 | +returnlineparts.current_expression_attribute(current_offset,line) |
| 533 | + |
| 534 | +defmatches(self,cursor_offset,line,**kwargs): |
| 535 | +if'locals_'notinkwargs: |
| 536 | +returnNone |
| 537 | +locals_=kwargs['locals_'] |
| 538 | + |
| 539 | +iflocals_isNone: |
| 540 | +locals_=__main__.__dict__ |
| 541 | + |
| 542 | +attr=self.locate(cursor_offset,line) |
| 543 | + |
| 544 | +try: |
| 545 | +obj=evaluate_current_expression(cursor_offset,line,locals_) |
| 546 | +exceptEvaluationError: |
| 547 | +returnset() |
| 548 | +withinspection.AttrCleaner(obj): |
| 549 | +# strips leading dot |
| 550 | +matches= [m[1:]forminself.attr_lookup(obj,'',attr.word)] |
| 551 | + |
| 552 | +ifattr.word.startswith('__'): |
| 553 | +pass |
| 554 | +elifattr.word.startswith('_'): |
| 555 | +matches=set(matchformatchinmatches |
| 556 | +ifnotmatch.startswith('__')) |
| 557 | +else: |
| 558 | +matches=set(matchformatchinmatches |
| 559 | +ifnotmatch.split('.')[-1].startswith('_')) |
| 560 | +returnmatches |
| 561 | + |
| 562 | + |
527 | 563 | try: |
528 | 564 | importjedi |
529 | 565 | exceptImportError: |
@@ -638,8 +674,9 @@ def get_default_completer(mode=SIMPLE): |
638 | 674 | CumulativeCompleter((GlobalCompletion(mode=mode), |
639 | 675 | ParameterNameCompletion(mode=mode)), |
640 | 676 | mode=mode), |
641 | | -ArrayItemMembersCompletion(mode=mode), |
642 | 677 | AttrCompletion(mode=mode), |
| 678 | +ExpressionAttributeCompletion(mode=mode), |
| 679 | +ArrayItemMembersCompletion(mode=mode), |
643 | 680 | ) |
644 | 681 |
|
645 | 682 |
|
|