From b847f4872c0fb24da3113dd524bf301b4b768589 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Wed, 2 Aug 2017 10:40:24 -0400 Subject: [PATCH] new scope names, strip parens from args, debug. --- SuperPython.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/SuperPython.py b/SuperPython.py index 5dfda73..77ecffd 100644 --- a/SuperPython.py +++ b/SuperPython.py @@ -22,12 +22,21 @@ def on_query_completions(self, view, prefix, locations): return current_row = self._get_row(view, target) try: - fn_region = self._find_closest_scope(view, 'entity.name.function.python', target, indent, current_row) - args_region = self._find_closest_scope(view, 'meta.function.parameters.python', target, indent, current_row) + fn_region = self._find_closest_scope( + view, 'entity.name.function.python', target, indent, + current_row) fn_indent = self._get_indent(view, fn_region) # search class scope with lower indentation level than founded function - cls_region = self._find_closest_scope(view, 'entity.name.type.class.python', target, fn_indent, current_row) - except IndexError: + cls_region = self._find_closest_scope( + view, 'entity.name.class.python', target, fn_indent, + current_row) + args_regions = view.find_by_selector( + 'meta.function.parameters.python') + args_regions = [ + m for m in args_regions if current_row > self._get_row(view, m) and + m.a >= fn_region.b and m.b < locations[0]] + except IndexError as e: + print(e) # We could't find some scope return @@ -39,7 +48,8 @@ def on_query_completions(self, view, prefix, locations): fn_name = view.substr(fn_region) cls_name = view.substr(cls_region) - args = view.substr(args_region) + args = ''.join(view.substr(m) for m in args_regions + ).lstrip('(').rstrip(')') if ',' in args: self_name, other_args = args.split(',', 1) @@ -53,6 +63,8 @@ def on_query_completions(self, view, prefix, locations): def _find_closest_scope(self, view, scope, target, min_indent, max_row): # use last found scope upper than current line and with smaller indentation level matches = view.find_by_selector(scope) + if not matches: + raise Exception("Cannot find " + scope) matches = [m for m in matches if self._get_indent(view, m) < min_indent and max_row > self._get_row(view, m)] return matches[-1]