| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6b7f681 commit 8be8f73
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,12 @@ | |||
| 10 | 10 | ||
| 11 | 11 | from bpython.lazyre import LazyReCompile | |
| 12 | 12 | ||
| 13 | - current_word_re = LazyReCompile(r'[\w_][\w0-9._]*[(]?') | ||
| 14 | 13 | LinePart = namedtuple('LinePart', ['start', 'stop', 'word']) | |
| 15 | 14 | ||
| 15 | + current_word_re = LazyReCompile( | ||
| 16 | + r'(?<![)\]\w_.])' | ||
| 17 | + r'([\w_][\w0-9._]*[(]?)') | ||
| 18 | + | ||
| 16 | 19 | ||
| 17 | 20 | def current_word(cursor_offset, line): | |
| 18 | 21 | """the object.attribute.attribute just before or under the cursor""" | |
@@ -22,10 +25,10 @@ def current_word(cursor_offset, line): | |||
| 22 | 25 | end = pos | |
| 23 | 26 | word = None | |
| 24 | 27 | for m in matches: | |
| 25 | - if m.start() < pos and m.end() >= pos: | ||
| 26 | - start = m.start() | ||
| 27 | - end = m.end() | ||
| 28 | - word = m.group() | ||
| 28 | + if m.start(1) < pos and m.end(1) >= pos: | ||
| 29 | + start = m.start(1) | ||
| 30 | + end = m.end(1) | ||
| 31 | + word = m.group(1) | ||
| 29 | 32 | if word is None: | |
| 30 | 33 | return None | |
| 31 | 34 | return LinePart(start, end, word) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | current_string, current_object, current_object_attribute, \ | |
| 6 | 6 | current_from_import_from, current_from_import_import, current_import, \ | |
| 7 | 7 | current_method_definition_name, current_single_word, \ | |
| 8 | - current_expression_attribute | ||
| 8 | + current_expression_attribute, current_dotted_attribute | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | def cursor(s): | |
@@ -129,6 +129,15 @@ def test_dots(self): | |||
| 129 | 129 | self.assertAccess('stuff[<asd|fg>]') | |
| 130 | 130 | self.assertAccess('stuff[asdf[<asd|fg>]') | |
| 131 | 131 | ||
| 132 | + def test_non_dots(self): | ||
| 133 | + self.assertAccess('].asdf|') | ||
| 134 | + self.assertAccess(').asdf|') | ||
| 135 | + self.assertAccess('foo[0].asdf|') | ||
| 136 | + self.assertAccess('foo().asdf|') | ||
| 137 | + self.assertAccess('foo().|') | ||
| 138 | + self.assertAccess('foo().asdf.|') | ||
| 139 | + self.assertAccess('foo[0].asdf.|') | ||
| 140 | + | ||
| 132 | 141 | def test_open_paren(self): | |
| 133 | 142 | self.assertAccess('<foo(|>') | |
| 134 | 143 | # documenting current behavior - TODO is this intended? | |
@@ -336,5 +345,16 @@ def test_strings(self): | |||
| 336 | 345 | self.assertAccess('"hey".<|>') | |
| 337 | 346 | ||
| 338 | 347 | ||
| 348 | + class TestCurrentDottedAttribute(LineTestCase): | ||
| 349 | + def setUp(self): | ||
| 350 | + self.func = current_dotted_attribute | ||
| 351 | + | ||
| 352 | + def test_simple(self): | ||
| 353 | + self.assertAccess('<obj.attr>|') | ||
| 354 | + self.assertAccess('(<obj.attr>|') | ||
| 355 | + self.assertAccess('[<obj.attr>|') | ||
| 356 | + self.assertAccess('m.body[0].value|') | ||
| 357 | + self.assertAccess('m.body[0].attr.value|') | ||
| 358 | + | ||
| 339 | 359 | if __name__ == '__main__': | |
| 340 | 360 | unittest.main() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments