1
0
forked from VimPlug/jedi

Remove a comprehension hack in the parser that would have made the diff parsers world hell.

This commit is contained in:
Dave Halter
2016-09-22 18:26:09 +02:00
parent c161e33119
commit e371b670f5
4 changed files with 15 additions and 8 deletions
+9 -1
View File
@@ -58,6 +58,13 @@ def filter_after_position(names, position, origin=None):
return names_new return names_new
def is_comprehension_name(name, origin):
definition = name.get_definition()
# TODO This is really hacky. It just compares the two definitions. This
# fails tests and is in general just a temporary way.
return definition.type == 'comp_for' and origin.get_definition().type != definition.type
def filter_definition_names(names, origin, position=None): def filter_definition_names(names, origin, position=None):
""" """
Filter names that are actual definitions in a scope. Names that are just Filter names that are actual definitions in a scope. Names that are just
@@ -73,7 +80,8 @@ def filter_definition_names(names, origin, position=None):
if not (isinstance(scope, er.FunctionExecution) and if not (isinstance(scope, er.FunctionExecution) and
isinstance(scope.base, er.LambdaWrapper)): isinstance(scope.base, er.LambdaWrapper)):
names = filter_after_position(names, position, origin) names = filter_after_position(names, position, origin)
names = [name for name in names if name.is_definition()] names = [name for name in names
if name.is_definition() and not is_comprehension_name(name, origin)]
# Private name mangling (compile.c) disallows access on names # Private name mangling (compile.c) disallows access on names
# preceeded by two underscores `__` if used outside of the class. Names # preceeded by two underscores `__` if used outside of the class. Names
-5
View File
@@ -193,11 +193,6 @@ class Parser(object):
arr = self._scope_names_stack[-1].setdefault(n.value, []) arr = self._scope_names_stack[-1].setdefault(n.value, [])
arr.append(n) arr.append(n)
new_node.names_dict = scope_names new_node.names_dict = scope_names
elif isinstance(new_node, pt.CompFor):
# The name definitions of comprehenions shouldn't be part of the
# current scope. They are part of the comprehension scope.
for n in new_node.get_defined_names():
self._scope_names_stack[-1][n.value].remove(n)
return new_node return new_node
def convert_leaf(self, grammar, type, value, prefix, start_pos): def convert_leaf(self, grammar, type, value, prefix, start_pos):
+5 -1
View File
@@ -173,6 +173,7 @@ class DiffParser(object):
self._old_module = self._new_module self._old_module = self._new_module
assert self._new_module.end_pos[0] == line_length assert self._new_module.end_pos[0] == line_length
return self._new_module return self._new_module
def _copy_from_old_parser(self, line_offset, until_line_old, until_line_new): def _copy_from_old_parser(self, line_offset, until_line_old, until_line_new):
@@ -225,6 +226,9 @@ class DiffParser(object):
self._update_positions(nodes, line_offset) self._update_positions(nodes, line_offset)
parent = self._insert_nodes(nodes) parent = self._insert_nodes(nodes)
self._update_names_dict(parent, nodes) self._update_names_dict(parent, nodes)
self._copied_ranges.append(
(nodes[0].start_pos[0], _get_last_line(nodes[-1]))
)
# We have copied as much as possible (but definitely not too # We have copied as much as possible (but definitely not too
# much). Therefore we just parse the rest. # much). Therefore we just parse the rest.
# We might not reach the end, because there's a statement # We might not reach the end, because there's a statement
@@ -469,7 +473,7 @@ class DiffParser(object):
for key, names in self._old_module.used_names.items(): for key, names in self._old_module.used_names.items():
for name in names: for name in names:
if name.start_pos[0] in copied_line_numbers: if name.start_pos[0] in copied_line_numbers:
new_used_names.setdefault(key, []).add(name) new_used_names.setdefault(key, []).append(name)
# Add an endmarker. # Add an endmarker.
last_leaf = self._new_module.last_leaf() last_leaf = self._new_module.last_leaf()
+1 -1
View File
@@ -130,7 +130,7 @@ On Linux, if environment variable ``$XDG_CACHE_HOME`` is set,
# parser # parser
# ---------------- # ----------------
fast_parser = True fast_parser = False
""" """
Use the fast parser. This means that reparsing is only being done if Use the fast parser. This means that reparsing is only being done if
something has been changed e.g. to a function. If this happens, only the something has been changed e.g. to a function. If this happens, only the