Skip to content

new scope names, strip parens from args, debug. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions SuperPython.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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]

Expand Down