1
0
forked from VimPlug/jedi

fix start_pos of multiple elements

This commit is contained in:
David Halter
2013-02-08 15:14:43 +01:00
parent 4f060ddcd9
commit 6c0a0e889c
4 changed files with 16 additions and 9 deletions

View File

@@ -190,12 +190,12 @@ class Script(object):
return scopes return scopes
def _get_under_cursor_stmt(self, cursor_txt): def _get_under_cursor_stmt(self, cursor_txt):
r = parsing.Parser(cursor_txt, no_docstr=True) offset = self.pos[0] - 1
r = parsing.Parser(cursor_txt, no_docstr=True, line_offset=offset)
try: try:
stmt = r.module.statements[0] stmt = r.module.statements[0]
except IndexError: except IndexError:
raise NotFoundError() raise NotFoundError()
stmt.start_pos = self.pos
stmt.parent = self._parser.user_scope stmt.parent = self._parser.user_scope
return stmt return stmt

View File

@@ -373,7 +373,8 @@ def find_name(scope, name_str, position=None, search_global=False,
if not result and isinstance(nscope, er.Instance): if not result and isinstance(nscope, er.Instance):
# __getattr__ / __getattribute__ # __getattr__ / __getattribute__
result += check_getattr(nscope, name_str) result += check_getattr(nscope, name_str)
debug.dbg('sfn filter "%s" in %s: %s' % (name_str, nscope, result)) debug.dbg('sfn filter "%s" in %s: %s@%s' % (name_str, nscope, result,
position))
return result return result
def descriptor_check(result): def descriptor_check(result):

View File

@@ -760,8 +760,7 @@ class Statement(Simple):
maybe_dict = array_type == Array.SET maybe_dict = array_type == Array.SET
break_tok = '' break_tok = ''
while True: while True:
stmt, break_tok = parse_array_el(token_iterator, stmt, break_tok = parse_array_el(token_iterator, maybe_dict)
start_pos, maybe_dict)
if stmt is None: if stmt is None:
break break
else: else:
@@ -782,17 +781,24 @@ class Statement(Simple):
else 0) else 0)
return arr return arr
def parse_array_el(token_iterator, start_pos, maybe_dict=False): def parse_array_el(token_iterator, maybe_dict=False):
token_list = [] token_list = []
level = 1 level = 1
tok = None tok = None
first = True
for i, tok_temp in token_iterator: for i, tok_temp in token_iterator:
try: try:
token_type, tok, start_tok_pos = tok_temp token_type, tok, start_tok_pos = tok_temp
end_pos = start_pos[0], start_pos[1] + len(tok) end_pos = start_tok_pos[0], start_tok_pos[1] + len(tok)
if first:
first = False
start_pos = start_tok_pos
except TypeError: except TypeError:
# the token is a Name, which has already been parsed # the token is a Name, which has already been parsed
tok = tok_temp tok = tok_temp
if first:
start_pos = tok.start_pos
first = False
end_pos = tok.end_pos end_pos = tok.end_pos
else: else:
if tok in closing_brackets: if tok in closing_brackets:
@@ -870,7 +876,7 @@ class Statement(Simple):
is_chain = True is_chain = True
elif tok == ',': # implies a tuple elif tok == ',': # implies a tuple
# rewrite `result`, because now the whole thing is a tuple # rewrite `result`, because now the whole thing is a tuple
add_el, t = parse_array_el(enumerate(result), start_pos) add_el, t = parse_array_el(enumerate(result))
arr = parse_array(token_iterator, Array.TUPLE, start_pos, arr = parse_array(token_iterator, Array.TUPLE, start_pos,
add_el) add_el)
result = [arr] result = [arr]

View File

@@ -35,7 +35,7 @@ class RecursionDecorator(object):
def push_stmt(self, stmt): def push_stmt(self, stmt):
self.current = RecursionNode(stmt, self.current) self.current = RecursionNode(stmt, self.current)
if self._check_recursion(): if self._check_recursion():
debug.warning('catched recursion', stmt) debug.warning('catched recursion', stmt, stmt.start_pos)
self.pop_stmt() self.pop_stmt()
return True return True
return False return False