mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-21 21:11:13 +08:00
get_code in Definition.description should not return first prefix.
This commit is contained in:
@@ -471,11 +471,10 @@ class Script(object):
|
||||
# The Evaluator.goto function checks for definitions, but since we
|
||||
# use a reverse tokenizer, we have new name_part objects, so we
|
||||
# have to check the user_stmt here for positions.
|
||||
if False and isinstance(user_stmt, pr.ExprStmt):
|
||||
if isinstance(user_stmt, pr.ExprStmt) \
|
||||
and isinstance(last_name.parent, pr.ExprStmt):
|
||||
for name in user_stmt.get_defined_names():
|
||||
if name.start_pos <= self._pos <= name.end_pos \
|
||||
and (not isinstance(name.parent, pr.Call)
|
||||
or name.parent.next is None):
|
||||
if name.start_pos <= self._pos <= name.end_pos:
|
||||
return [name]
|
||||
|
||||
defs = self._evaluator.goto(last_name)
|
||||
|
||||
@@ -591,7 +591,14 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
||||
# only show module name
|
||||
d = 'module %s' % self.module_name
|
||||
else:
|
||||
first_leaf = d.first_leaf()
|
||||
# Remove the prefix, because that's not what we want for get_code
|
||||
# here.
|
||||
old, first_leaf.prefix = first_leaf.prefix, ''
|
||||
try:
|
||||
d = d.get_code().replace('\n', '').replace('\r', '')
|
||||
finally:
|
||||
first_leaf.prefix = old
|
||||
return d
|
||||
|
||||
@property
|
||||
|
||||
@@ -443,6 +443,10 @@ class Evaluator(object):
|
||||
return self.eval_element(call)
|
||||
|
||||
def goto(self, name):
|
||||
stmt = name.parent
|
||||
if isinstance(stmt, pr.ExprStmt) and name in stmt.get_defined_names():
|
||||
return [name]
|
||||
|
||||
scope = name.get_parent_scope()
|
||||
if pr.is_node(name.parent, 'trailer'):
|
||||
call = call_of_name(name, cut_own_trailer=True)
|
||||
|
||||
@@ -445,6 +445,13 @@ class Simple(Base):
|
||||
return result
|
||||
return None
|
||||
|
||||
def first_leaf(self):
|
||||
try:
|
||||
return self.children[0].first_leaf()
|
||||
except AttributeError:
|
||||
return self.children[0]
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
code = self.get_code().replace('\n', ' ')
|
||||
if not is_py3:
|
||||
|
||||
Reference in New Issue
Block a user