Fix a few more issues, mostly with the fast parser.

This commit is contained in:
Dave Halter
2016-06-13 18:21:17 +02:00
parent a485412af0
commit 27f05de3b7
5 changed files with 20 additions and 4 deletions

View File

@@ -442,13 +442,15 @@ class Evaluator(object):
def_ = name.get_definition() def_ = name.get_definition()
is_simple_name = name.parent.type not in ('power', 'trailer') is_simple_name = name.parent.type not in ('power', 'trailer')
if is_simple_name: if is_simple_name:
if name.parent.type in ('file_input', 'classdef', 'funcdef'):
return [self.wrap(name.parent)]
if def_.type == 'expr_stmt' and name in def_.get_defined_names(): if def_.type == 'expr_stmt' and name in def_.get_defined_names():
return self.eval_statement(def_, name) return self.eval_statement(def_, name)
elif def_.type == 'for_stmt': elif def_.type == 'for_stmt':
container_types = self.eval_element(def_.children[3]) container_types = self.eval_element(def_.children[3])
for_types = iterable.py__iter__types(self, container_types, def_.children[3]) for_types = iterable.py__iter__types(self, container_types, def_.children[3])
return finder.check_tuple_assignments(self, for_types, name) return finder.check_tuple_assignments(self, for_types, name)
elif def_.type == 'import_from': elif def_.type in ('import_from', 'import_name'):
return imports.ImportWrapper(self, name).follow() return imports.ImportWrapper(self, name).follow()
call = helpers.call_of_name(name) call = helpers.call_of_name(name)

View File

@@ -191,6 +191,7 @@ class Parser(object):
self.remove_last_newline() self.remove_last_newline()
def get_parsed_node(self): def get_parsed_node(self):
# TODO rename to get_root_node
return self._parsed return self._parsed
def _tokenize(self, tokenizer): def _tokenize(self, tokenizer):

View File

@@ -259,6 +259,9 @@ class FastParser(use_metaclass(CachedFastParser)):
self.module = FastModule(self.module_path) self.module = FastModule(self.module_path)
self.root_node = self.current_node = ParserNode(self.module, self, '') self.root_node = self.current_node = ParserNode(self.module, self, '')
def get_parsed_node(self):
return self.module
def update(self, source): def update(self, source):
# Variables for testing purposes: It is important that the number of # Variables for testing purposes: It is important that the number of
# parsers used can be minimized. With these variables we can test # parsers used can be minimized. With these variables we can test
@@ -326,13 +329,13 @@ class FastParser(use_metaclass(CachedFastParser)):
current_lines.append(l) # Just ignore comments and blank lines current_lines.append(l) # Just ignore comments and blank lines
continue continue
if new_indent: if new_indent and not parentheses_level:
if indent > indent_list[-2]: if indent > indent_list[-2]:
# Set the actual indent, not just the random old indent + 1. # Set the actual indent, not just the random old indent + 1.
indent_list[-1] = indent indent_list[-1] = indent
new_indent = False new_indent = False
while indent <= indent_list[-2]: # -> dedent while indent < indent_list[-1]: # -> dedent
indent_list.pop() indent_list.pop()
# This automatically resets the flow_indent if there was a # This automatically resets the flow_indent if there was a
# dedent or a flow just on one line (with one simple_stmt). # dedent or a flow just on one line (with one simple_stmt).

View File

@@ -469,3 +469,13 @@ def test_decorator_string_issue():
s = jedi.Script(source) s = jedi.Script(source)
assert s.completions() assert s.completions()
assert s._parser.module().get_code() == source assert s._parser.module().get_code() == source
def test_round_trip():
source = dedent('''
def x():
"""hahaha"""
func''')
f = FastParser(load_grammar(), source)
assert f.get_parsed_node().get_code() == source

View File

@@ -146,7 +146,7 @@ class TestRegression(TestCase):
x = 0 x = 0
a = \ a = \
[1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here [1, 2, 3, 4, 5, 6, 7, 8, 9, (x)] # <-- here
""", '(x)] # <-- here', []) """, '(x)] # <-- here', ['int'])
def test_generator(self): def test_generator(self):
# Did have some problems with the usage of generator completions this # Did have some problems with the usage of generator completions this