| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 51ecedb commit ce0bd0a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -340,63 +340,6 @@ def list_attributes(self, obj): | |||
| 340 | 340 | return dir(obj) | |
| 341 | 341 | ||
| 342 | 342 | ||
| 343 | - class ArrayItemMembersCompletion(BaseCompletionType): | ||
| 344 | - | ||
| 345 | - def __init__(self, shown_before_tab=True, mode=SIMPLE): | ||
| 346 | - self._shown_before_tab = shown_before_tab | ||
| 347 | - self.completer = AttrCompletion(mode=mode) | ||
| 348 | - | ||
| 349 | - def matches(self, cursor_offset, line, **kwargs): | ||
| 350 | - if 'locals_' not in kwargs: | ||
| 351 | - return None | ||
| 352 | - locals_ = kwargs['locals_'] | ||
| 353 | - | ||
| 354 | - full = self.locate(cursor_offset, line) | ||
| 355 | - if full is None: | ||
| 356 | - return None | ||
| 357 | - | ||
| 358 | - arr = lineparts.current_indexed_member_access_identifier( | ||
| 359 | - cursor_offset, line) | ||
| 360 | - index = lineparts.current_indexed_member_access_identifier_with_index( | ||
| 361 | - cursor_offset, line) | ||
| 362 | - member = lineparts.current_indexed_member_access_member( | ||
| 363 | - cursor_offset, line) | ||
| 364 | - | ||
| 365 | - try: | ||
| 366 | - obj = safe_eval(arr.word, locals_) | ||
| 367 | - except EvaluationError: | ||
| 368 | - return None | ||
| 369 | - if type(obj) not in (list, tuple) + string_types: | ||
| 370 | - # then is may be unsafe to do attribute lookup on it | ||
| 371 | - return None | ||
| 372 | - | ||
| 373 | - try: | ||
| 374 | - locals_['temp_val_from_array'] = safe_eval(index.word, locals_) | ||
| 375 | - except (EvaluationError, IndexError): | ||
| 376 | - return None | ||
| 377 | - | ||
| 378 | - temp_line = line.replace(index.word, 'temp_val_from_array.') | ||
| 379 | - | ||
| 380 | - matches = self.completer.matches(len(temp_line), temp_line, **kwargs) | ||
| 381 | - if matches is None: | ||
| 382 | - return None | ||
| 383 | - | ||
| 384 | - matches_with_correct_name = \ | ||
| 385 | - set(match.replace('temp_val_from_array.', index.word+'.') | ||
| 386 | - for match in matches if match[20:].startswith(member.word)) | ||
| 387 | - | ||
| 388 | - del locals_['temp_val_from_array'] | ||
| 389 | - | ||
| 390 | - return matches_with_correct_name | ||
| 391 | - | ||
| 392 | - def locate(self, current_offset, line): | ||
| 393 | - a = lineparts.current_indexed_member_access(current_offset, line) | ||
| 394 | - return a | ||
| 395 | - | ||
| 396 | - def format(self, match): | ||
| 397 | - return after_last_dot(match) | ||
| 398 | - | ||
| 399 | - | ||
| 400 | 343 | class DictKeyCompletion(BaseCompletionType): | |
| 401 | 344 | ||
| 402 | 345 | def matches(self, cursor_offset, line, **kwargs): | |
@@ -526,8 +469,7 @@ def locate(self, current_offset, line): | |||
| 526 | 469 | ||
| 527 | 470 | ||
| 528 | 471 | class ExpressionAttributeCompletion(AttrCompletion): | |
| 529 | - # could replace ArrayItemMember completion and attr completion | ||
| 530 | - # as a more general case | ||
| 472 | + # could replace attr completion as a more general case with some work | ||
| 531 | 473 | def locate(self, current_offset, line): | |
| 532 | 474 | return lineparts.current_expression_attribute(current_offset, line) | |
| 533 | 475 | ||
@@ -676,7 +618,6 @@ def get_default_completer(mode=SIMPLE): | |||
| 676 | 618 | mode=mode), | |
| 677 | 619 | AttrCompletion(mode=mode), | |
| 678 | 620 | ExpressionAttributeCompletion(mode=mode), | |
| 679 | - ArrayItemMembersCompletion(mode=mode), | ||
| 680 | 621 | ) | |
| 681 | 622 | ||
| 682 | 623 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,20 +268,20 @@ def __getattr__(self, attr): | |||
| 268 | 268 | self.com.matches(4, 'a.__', locals_=locals_)) | |
| 269 | 269 | ||
| 270 | 270 | ||
| 271 | - class TestArrayItemCompletion(unittest.TestCase): | ||
| 271 | + class TestExpressionAttributeCompletion(unittest.TestCase): | ||
| 272 | 272 | @classmethod | |
| 273 | 273 | def setUpClass(cls): | |
| 274 | - cls.com = autocomplete.ArrayItemMembersCompletion() | ||
| 274 | + cls.com = autocomplete.ExpressionAttributeCompletion() | ||
| 275 | 275 | ||
| 276 | 276 | def test_att_matches_found_on_instance(self): | |
| 277 | 277 | self.assertSetEqual(self.com.matches(5, 'a[0].', locals_={'a': [Foo()]}), | |
| 278 | - set(['a[0].method', 'a[0].a', 'a[0].b'])) | ||
| 278 | + set(['method', 'a', 'b'])) | ||
| 279 | 279 | ||
| 280 | 280 | @skip_old_style | |
| 281 | 281 | def test_att_matches_found_on_old_style_instance(self): | |
| 282 | 282 | self.assertSetEqual(self.com.matches(5, 'a[0].', | |
| 283 | 283 | locals_={'a': [OldStyleFoo()]}), | |
| 284 | - set(['a[0].method', 'a[0].a', 'a[0].b'])) | ||
| 284 | + set(['method', 'a', 'b'])) | ||
| 285 | 285 | ||
| 286 | 286 | def test_other_getitem_methods_not_called(self): | |
| 287 | 287 | class FakeList(object): | |
@@ -293,14 +293,14 @@ def __getitem__(inner_self, i): | |||
| 293 | 293 | def test_tuples_complete(self): | |
| 294 | 294 | self.assertSetEqual(self.com.matches(5, 'a[0].', | |
| 295 | 295 | locals_={'a': (Foo(),)}), | |
| 296 | - set(['a[0].method', 'a[0].a', 'a[0].b'])) | ||
| 296 | + set(['method', 'a', 'b'])) | ||
| 297 | 297 | ||
| 298 | 298 | @unittest.skip('TODO, subclasses do not complete yet') | |
| 299 | 299 | def test_list_subclasses_complete(self): | |
| 300 | 300 | class ListSubclass(list): pass | |
| 301 | 301 | self.assertSetEqual(self.com.matches(5, 'a[0].', | |
| 302 | 302 | locals_={'a': ListSubclass([Foo()])}), | |
| 303 | - set(['a[0].method', 'a[0].a', 'a[0].b'])) | ||
| 303 | + set(['method', 'a', 'b'])) | ||
| 304 | 304 | ||
| 305 | 305 | def test_getitem_not_called_in_list_subclasses_overriding_getitem(self): | |
| 306 | 306 | class FakeList(list): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments