diff --git a/jedi/api.py b/jedi/api.py index aba7fbee..751026bd 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -348,8 +348,6 @@ class Script(object): # just take entry zero, because we need just one. executable = origins[0] - after = self.module.get_line(self.pos[0])[self.pos[1]:] - index -= re.search('^[ ,]*', after).group(0).count(',') return api_classes.CallDef(executable, index, call) def _get_on_import_stmt(self, is_like_search=False): diff --git a/jedi/helpers.py b/jedi/helpers.py index e835bc3b..9f3b4bf0 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -1,7 +1,6 @@ import copy import weakref -from _compatibility import hasattr import parsing import evaluate import debug @@ -201,10 +200,16 @@ def scan_array_for_pos(arr, pos): """ Returns the function Call that match search_name in an Array. """ - index = 0 + def check_arr_index(): + positions = arr.arr_el_pos + for index, comma_pos in enumerate(positions): + if pos < comma_pos: + return index + return len(positions) + call = None stop = False - for index, sub in enumerate(arr.values): + for sub in arr.values: call = None for s in sub: if isinstance(s, parsing.Array): @@ -215,9 +220,10 @@ def scan_array_for_pos(arr, pos): return call, index, stop elif isinstance(s, parsing.Call): start_s = s + # check parts of calls while s is not None: if s.start_pos >= pos: - return call, index, stop + return call, check_arr_index(), stop elif s.execution is not None: end = s.execution.end_pos if s.execution.start_pos < pos and \ @@ -242,4 +248,4 @@ def scan_array_for_pos(arr, pos): # The third return is just necessary for recursion inside, because # it needs to know when to stop iterating. - return call, index, stop + return call, check_arr_index(), stop diff --git a/jedi/parsing.py b/jedi/parsing.py index 570643bc..739a8649 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -819,7 +819,7 @@ class Statement(Simple): while is_call_or_close(): result = result.parent() close_brackets = False - result.add_field() + result.add_field((start_pos[0], start_pos[1] + 1)) # important - it cannot be empty anymore if result.type == Array.NOARRAY: result.type = Array.TUPLE @@ -986,16 +986,18 @@ class Array(Call): parent) self.values = values if values else [] + self.arr_el_pos = [] self.keys = [] self.end_pos = None - def add_field(self): + def add_field(self, start_pos): """ Just add a new field to the values. Each value has a sub-array, because there may be different tokens in one array. """ + self.arr_el_pos.append(start_pos) self.values.append([]) def add_to_current_field(self, tok):