From 53e49627116222fae94b47ed950b4731f382e620 Mon Sep 17 00:00:00 2001 From: Jean-Louis Fuchs Date: Thu, 12 Dec 2013 22:11:15 +0100 Subject: [PATCH] * started create paralell get_code --- jedi/parser/representation.py | 36 +++++++++++++++++++++++++++++++++++ test/test_get_code.py | 16 +++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index c0e931f6..ef4017a4 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -46,6 +46,15 @@ from jedi import common from jedi import debug +class GetCodeState(object): + """A helper class for passing the state of get_code in a thread-safe + manner""" + __slots__ = ("last_pos") + + def __init__(self): + self.last_pos = (0, 0) + + class Base(object): """ This is just here to have an isinstance check, which is also used on @@ -60,6 +69,29 @@ class Base(object): def isinstance(self, *cls): return isinstance(self, cls) + @property + def newline(self): + """Returns the newline type for the current code.""" + #TODO: we need newline detection + return "\n" + + @property + def whitespace(self): + """Returns the whitespace type for the current code: tab or space.""" + #TODO: we need tab detection + return " " + + def space(self, from_pos, to_pos): + """Return the space between two tokens""" + linecount = to_pos[0] - from_pos[0] + if linecount == 0: + return self.whitespace * (to_pos[1] - from_pos[1]) + else: + return "%s%s" % ( + self.newline * linecount, + self.whitespace * to_pos[1], + ) + class Simple(Base): """ @@ -191,6 +223,10 @@ class Scope(Simple, IsScope): i += s.get_imports() return i + def get_code2(self, state=GetCodeState()): + string = [] + return "".join(string) + def get_code(self, first_indent=False, indention=' '): """ :return: Returns the code of the current scope. diff --git a/test/test_get_code.py b/test/test_get_code.py index 58932e6e..d2db1184 100644 --- a/test/test_get_code.py +++ b/test/test_get_code.py @@ -2,11 +2,18 @@ import jedi.parser as parser import difflib code_basic_features = ''' +"""A mod docstring""" + def a_function(a_argument, a_default = "default"): - """A docstring""" + """A func docstring""" a_result = 3 * a_argument print(a_result) # a comment + b = """ +from +to""" + "huhu" + + if a_default == "default": return str(a_result) else @@ -22,7 +29,10 @@ def diff_code_assert(a, b, n=4): n=n, lineterm="" )) - assert False, "Code does not match:\n%s" % diff + assert False, "Code does not match:\n%s\n\ncreated code:\n%s" % ( + diff, + b + ) pass @@ -32,5 +42,5 @@ def test_basic_parsing(): prs = parser.Parser(code_basic_features) diff_code_assert( code_basic_features, - prs.top_module.get_code() + prs.top_module.get_code2() )