forked from VimPlug/jedi
improved parents in fast parser
This commit is contained in:
@@ -265,25 +265,30 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
current_lines.append(l)
|
current_lines.append(l)
|
||||||
add_part()
|
add_part()
|
||||||
|
|
||||||
|
|
||||||
print parts[1]
|
|
||||||
print [p[:20] for p in parts]
|
|
||||||
exit()
|
|
||||||
return parts
|
return parts
|
||||||
|
|
||||||
def _parse(self, code):
|
def _parse(self, code):
|
||||||
""" :type code: str """
|
""" :type code: str """
|
||||||
parts = self._split_parts(code)
|
def set_parent(module):
|
||||||
r = r'(?:\n(?:def|class|@.*?\n(?:def|class))|^).*?' \
|
def get_indent(module):
|
||||||
r'(?=\n(?:def|class|@)|$)'
|
try:
|
||||||
parts = re.findall(r, code, re.DOTALL)
|
el = module.subscopes[0]
|
||||||
|
except IndexError:
|
||||||
|
try:
|
||||||
|
el = module.statements[0]
|
||||||
|
except IndexError:
|
||||||
|
el = module.imports[0]
|
||||||
|
return el.start_pos[1]
|
||||||
|
|
||||||
if len(parts) > 1 and not re.match('def|class|@', parts[0]):
|
if self.parsers:
|
||||||
# Merge the first two because `common.NoErrorTokenizer` is not able
|
new_indent = get_indent(module)
|
||||||
# to know if there's a class/func or not.
|
old_indent = get_indent(self.parsers[-1].module)
|
||||||
# Therefore every part has it's own class/func. Exactly one.
|
if old_indent < new_indent:
|
||||||
parts[0] += parts[1]
|
module.parent = self.parsers[-1].module.subscopes[0]
|
||||||
parts.pop(1)
|
return
|
||||||
|
p.module.parent = self.module
|
||||||
|
|
||||||
|
parts = self._split_parts(code)
|
||||||
|
|
||||||
if settings.fast_parser_always_reparse:
|
if settings.fast_parser_always_reparse:
|
||||||
self.parsers[:] = []
|
self.parsers[:] = []
|
||||||
@@ -321,12 +326,12 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
else:
|
else:
|
||||||
p = parsing.Parser(code[start:],
|
p = parsing.Parser(code[start:],
|
||||||
self.module_path, self.user_position,
|
self.module_path, self.user_position,
|
||||||
offset=(line_offset, 0), stop_on_scope=True,
|
offset=(line_offset, 0), is_fast_parser=True,
|
||||||
top_module=self.module)
|
top_module=self.module)
|
||||||
|
|
||||||
p.hash = h
|
p.hash = h
|
||||||
p.code = code_part
|
p.code = code_part
|
||||||
p.module.parent = self.module
|
set_parent(p.module)
|
||||||
self.parsers.insert(parser_order, p)
|
self.parsers.insert(parser_order, p)
|
||||||
|
|
||||||
parser_order += 1
|
parser_order += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user