forked from VimPlug/jedi
Replace first_leaf and last_leaf with get_first_leaf and get_last_leaf.
This commit is contained in:
@@ -44,7 +44,7 @@ def _merge_used_names(base_dict, other_dict):
|
|||||||
|
|
||||||
|
|
||||||
def _get_last_line(node_or_leaf):
|
def _get_last_line(node_or_leaf):
|
||||||
last_leaf = node_or_leaf.last_leaf()
|
last_leaf = node_or_leaf.get_last_leaf()
|
||||||
if _ends_with_newline(last_leaf):
|
if _ends_with_newline(last_leaf):
|
||||||
return last_leaf.start_pos[0]
|
return last_leaf.start_pos[0]
|
||||||
else:
|
else:
|
||||||
@@ -267,7 +267,7 @@ class DiffParser(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
line = self._nodes_stack.parsed_until_line + 1
|
line = self._nodes_stack.parsed_until_line + 1
|
||||||
node = self._new_module.last_leaf()
|
node = self._new_module.get_last_leaf()
|
||||||
while True:
|
while True:
|
||||||
parent = node.parent
|
parent = node.parent
|
||||||
if parent.type in ('suite', 'file_input'):
|
if parent.type in ('suite', 'file_input'):
|
||||||
@@ -426,7 +426,7 @@ class _NodesStackNode(object):
|
|||||||
assert not self.parent
|
assert not self.parent
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
last_leaf = self.children_groups[-1].children[-1].last_leaf()
|
last_leaf = self.children_groups[-1].children[-1].get_last_leaf()
|
||||||
line = last_leaf.end_pos[0]
|
line = last_leaf.end_pos[0]
|
||||||
|
|
||||||
# Calculate the line offsets
|
# Calculate the line offsets
|
||||||
@@ -500,7 +500,7 @@ class _NodesStack(object):
|
|||||||
"""
|
"""
|
||||||
Helps cleaning up the tree nodes that get inserted.
|
Helps cleaning up the tree nodes that get inserted.
|
||||||
"""
|
"""
|
||||||
last_leaf = tree_nodes[-1].last_leaf()
|
last_leaf = tree_nodes[-1].get_last_leaf()
|
||||||
is_endmarker = last_leaf.type == self.endmarker_type
|
is_endmarker = last_leaf.type == self.endmarker_type
|
||||||
self._last_prefix = ''
|
self._last_prefix = ''
|
||||||
if is_endmarker:
|
if is_endmarker:
|
||||||
@@ -515,7 +515,7 @@ class _NodesStack(object):
|
|||||||
last_leaf.prefix, self._last_prefix = \
|
last_leaf.prefix, self._last_prefix = \
|
||||||
last_leaf.prefix[:separation + 1], last_leaf.prefix[separation + 1:]
|
last_leaf.prefix[:separation + 1], last_leaf.prefix[separation + 1:]
|
||||||
|
|
||||||
first_leaf = tree_nodes[0].first_leaf()
|
first_leaf = tree_nodes[0].get_first_leaf()
|
||||||
first_leaf.prefix = self.prefix + first_leaf.prefix
|
first_leaf.prefix = self.prefix + first_leaf.prefix
|
||||||
self.prefix = ''
|
self.prefix = ''
|
||||||
|
|
||||||
@@ -592,13 +592,13 @@ class _NodesStack(object):
|
|||||||
new_nodes.pop()
|
new_nodes.pop()
|
||||||
while new_nodes:
|
while new_nodes:
|
||||||
last_node = new_nodes[-1]
|
last_node = new_nodes[-1]
|
||||||
if last_node.last_leaf().type == 'newline':
|
if last_node.get_last_leaf().type == 'newline':
|
||||||
break
|
break
|
||||||
new_nodes.pop()
|
new_nodes.pop()
|
||||||
|
|
||||||
if new_nodes:
|
if new_nodes:
|
||||||
try:
|
try:
|
||||||
last_line_offset_leaf = new_nodes[line_offset_index].last_leaf()
|
last_line_offset_leaf = new_nodes[line_offset_index].get_last_leaf()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
line_offset = 0
|
line_offset = 0
|
||||||
# In this case we don't have to calculate an offset, because
|
# In this case we don't have to calculate an offset, because
|
||||||
@@ -621,7 +621,7 @@ class _NodesStack(object):
|
|||||||
|
|
||||||
# Add an endmarker.
|
# Add an endmarker.
|
||||||
try:
|
try:
|
||||||
last_leaf = self._module.last_leaf()
|
last_leaf = self._module.get_last_leaf()
|
||||||
end_pos = list(last_leaf.end_pos)
|
end_pos = list(last_leaf.end_pos)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
end_pos = [1, 0]
|
end_pos = [1, 0]
|
||||||
|
|||||||
@@ -298,10 +298,10 @@ class Leaf(Base):
|
|||||||
def move(self, line_offset):
|
def move(self, line_offset):
|
||||||
self.line += line_offset
|
self.line += line_offset
|
||||||
|
|
||||||
def first_leaf(self):
|
def get_first_leaf(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def last_leaf(self):
|
def get_last_leaf(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_code(self, normalized=False, include_prefix=True):
|
def get_code(self, normalized=False, include_prefix=True):
|
||||||
@@ -560,14 +560,11 @@ class BaseNode(Base):
|
|||||||
pass # Must be a non-scope
|
pass # Must be a non-scope
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def first_leaf(self):
|
def get_first_leaf(self):
|
||||||
try:
|
return self.children[0].get_first_leaf()
|
||||||
return self.children[0].first_leaf()
|
|
||||||
except AttributeError:
|
|
||||||
return self.children[0]
|
|
||||||
|
|
||||||
def last_leaf(self):
|
def get_last_leaf(self):
|
||||||
return self.children[-1].last_leaf()
|
return self.children[-1].get_last_leaf()
|
||||||
|
|
||||||
def get_following_comment_same_line(self):
|
def get_following_comment_same_line(self):
|
||||||
"""
|
"""
|
||||||
@@ -576,11 +573,11 @@ class BaseNode(Base):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if self.type == 'for_stmt':
|
if self.type == 'for_stmt':
|
||||||
whitespace = self.children[5].first_leaf().prefix
|
whitespace = self.children[5].get_first_leaf().prefix
|
||||||
elif self.type == 'with_stmt':
|
elif self.type == 'with_stmt':
|
||||||
whitespace = self.children[3].first_leaf().prefix
|
whitespace = self.children[3].get_first_leaf().prefix
|
||||||
else:
|
else:
|
||||||
whitespace = self.last_leaf().get_next_leaf().prefix
|
whitespace = self.get_last_leaf().get_next_leaf().prefix
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None
|
return None
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -1120,7 +1117,7 @@ class Flow(BaseNode):
|
|||||||
for i, child in enumerate(self.children):
|
for i, child in enumerate(self.children):
|
||||||
if start_pos < child.start_pos:
|
if start_pos < child.start_pos:
|
||||||
return keyword
|
return keyword
|
||||||
first_leaf = child.first_leaf()
|
first_leaf = child.get_first_leaf()
|
||||||
if first_leaf in self.FLOW_KEYWORDS:
|
if first_leaf in self.FLOW_KEYWORDS:
|
||||||
keyword = first_leaf
|
keyword = first_leaf
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user