mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 10:07:06 +08:00
* started create paralell get_code
This commit is contained in:
@@ -46,6 +46,15 @@ from jedi import common
|
|||||||
from jedi import debug
|
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):
|
class Base(object):
|
||||||
"""
|
"""
|
||||||
This is just here to have an isinstance check, which is also used on
|
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):
|
def isinstance(self, *cls):
|
||||||
return 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):
|
class Simple(Base):
|
||||||
"""
|
"""
|
||||||
@@ -191,6 +223,10 @@ class Scope(Simple, IsScope):
|
|||||||
i += s.get_imports()
|
i += s.get_imports()
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
def get_code2(self, state=GetCodeState()):
|
||||||
|
string = []
|
||||||
|
return "".join(string)
|
||||||
|
|
||||||
def get_code(self, first_indent=False, indention=' '):
|
def get_code(self, first_indent=False, indention=' '):
|
||||||
"""
|
"""
|
||||||
:return: Returns the code of the current scope.
|
:return: Returns the code of the current scope.
|
||||||
|
|||||||
@@ -2,11 +2,18 @@ import jedi.parser as parser
|
|||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
code_basic_features = '''
|
code_basic_features = '''
|
||||||
|
"""A mod docstring"""
|
||||||
|
|
||||||
def a_function(a_argument, a_default = "default"):
|
def a_function(a_argument, a_default = "default"):
|
||||||
"""A docstring"""
|
"""A func docstring"""
|
||||||
|
|
||||||
a_result = 3 * a_argument
|
a_result = 3 * a_argument
|
||||||
print(a_result) # a comment
|
print(a_result) # a comment
|
||||||
|
b = """
|
||||||
|
from
|
||||||
|
to""" + "huhu"
|
||||||
|
|
||||||
|
|
||||||
if a_default == "default":
|
if a_default == "default":
|
||||||
return str(a_result)
|
return str(a_result)
|
||||||
else
|
else
|
||||||
@@ -22,7 +29,10 @@ def diff_code_assert(a, b, n=4):
|
|||||||
n=n,
|
n=n,
|
||||||
lineterm=""
|
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
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -32,5 +42,5 @@ def test_basic_parsing():
|
|||||||
prs = parser.Parser(code_basic_features)
|
prs = parser.Parser(code_basic_features)
|
||||||
diff_code_assert(
|
diff_code_assert(
|
||||||
code_basic_features,
|
code_basic_features,
|
||||||
prs.top_module.get_code()
|
prs.top_module.get_code2()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user