1
0
forked from VimPlug/jedi

* started create paralell get_code

This commit is contained in:
Jean-Louis Fuchs
2013-12-12 22:11:15 +01:00
parent 0e00aa103f
commit 53e4962711
2 changed files with 49 additions and 3 deletions

View File

@@ -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.