forked from VimPlug/jedi
Add printing for all the different kinds of completions in sith.py run
This kind of printing should probably go in the objects themselves, but I was too disgusted by the completion APIs to even begin to start extending the code for that (it needs to be cleaned up first).
This commit is contained in:
59
sith.py
59
sith.py
@@ -108,16 +108,16 @@ class TestCase(object):
|
|||||||
column = random.randint(0, len(lines[line - 1]))
|
column = random.randint(0, len(lines[line - 1]))
|
||||||
return cls(operation, path, line, column)
|
return cls(operation, path, line, column)
|
||||||
|
|
||||||
def run(self, debugger, record=None, print_completions=False):
|
def run(self, debugger, record=None, print_result=False):
|
||||||
try:
|
try:
|
||||||
with open(self.path) as f:
|
with open(self.path) as f:
|
||||||
self.file = f.read()
|
self.file = f.read()
|
||||||
self.script = jedi.Script(self.file, self.line, self.column,
|
self.script = jedi.Script(self.file, self.line, self.column,
|
||||||
self.path)
|
self.path)
|
||||||
self.completions = getattr(self.script, self.operation)()
|
self.completions = getattr(self.script, self.operation)()
|
||||||
if print_completions:
|
if print_result:
|
||||||
self.show_location()
|
self.show_location(self.line, self.column)
|
||||||
self.show_completions()
|
self.show_operation()
|
||||||
except jedi.NotFoundError:
|
except jedi.NotFoundError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -135,20 +135,55 @@ class TestCase(object):
|
|||||||
pdb.post_mortem(einfo[2])
|
pdb.post_mortem(einfo[2])
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def show_location(self):
|
def show_location(self, lineno, column, show=3):
|
||||||
# Three lines ought to be enough
|
# Three lines ought to be enough
|
||||||
show = 3
|
lower = lineno - show if lineno - show > 0 else 0
|
||||||
lower = self.line - show if self.line - show > 0 else 0
|
for i, line in enumerate(self.file.split('\n')[lower:lineno]):
|
||||||
for i, line in enumerate(self.file.split('\n')[lower:self.line]):
|
|
||||||
print(lower + i + 1, line)
|
print(lower + i + 1, line)
|
||||||
print(' '*(self.column + len(str(self.line))), '^')
|
print(' '*(column + len(str(lineno))), '^')
|
||||||
|
|
||||||
|
def show_operation(self):
|
||||||
|
print("%s:\n" % self.operation.capitalize())
|
||||||
|
if self.operation == 'completions':
|
||||||
|
self.show_completions()
|
||||||
|
elif self.operation == 'goto_assignments':
|
||||||
|
self.show_goto_assignments()
|
||||||
|
elif self.operation == 'goto_definitions':
|
||||||
|
self.show_goto_definitions()
|
||||||
|
elif self.operation == 'usages':
|
||||||
|
self.show_usages()
|
||||||
|
elif self.operation == 'call_signatures':
|
||||||
|
self.show_call_signatures()
|
||||||
|
|
||||||
def show_completions(self):
|
def show_completions(self):
|
||||||
print("Completions:")
|
|
||||||
print()
|
|
||||||
for completion in self.completions:
|
for completion in self.completions:
|
||||||
print(completion.name)
|
print(completion.name)
|
||||||
|
|
||||||
|
# TODO: Support showing the location in other files
|
||||||
|
|
||||||
|
# TODO: Move this printing to the completion objects themselves
|
||||||
|
def show_usages(self):
|
||||||
|
for completion in self.completions:
|
||||||
|
print(completion.description)
|
||||||
|
if os.path.abspath(completion.module_path) == os.path.abspath(self.path):
|
||||||
|
self.show_location(completion.line, completion.column)
|
||||||
|
|
||||||
|
def show_call_signatures(self):
|
||||||
|
for completion in self.completions:
|
||||||
|
# This is too complicated to print. It really should be
|
||||||
|
# implemented in str() anyway.
|
||||||
|
print(completion)
|
||||||
|
# Can't print the location here because we don't have the module path
|
||||||
|
|
||||||
|
|
||||||
|
def show_goto_definitions(self):
|
||||||
|
for completion in self.completions:
|
||||||
|
print(completion.desc_with_module)
|
||||||
|
if os.path.abspath(completion.module_path) == os.path.abspath(self.path):
|
||||||
|
self.show_location(completion.line, completion.column)
|
||||||
|
|
||||||
|
show_goto_assignments = show_goto_definitions
|
||||||
|
|
||||||
def show_errors(self):
|
def show_errors(self):
|
||||||
print(self.traceback)
|
print(self.traceback)
|
||||||
print(("Error with running Script(...).{operation}() with\n"
|
print(("Error with running Script(...).{operation}() with\n"
|
||||||
@@ -175,7 +210,7 @@ def main(arguments):
|
|||||||
elif arguments['run']:
|
elif arguments['run']:
|
||||||
TestCase(arguments['<operation>'], arguments['<path>'],
|
TestCase(arguments['<operation>'], arguments['<path>'],
|
||||||
int(arguments['<line>']), int(arguments['<column>'])
|
int(arguments['<line>']), int(arguments['<column>'])
|
||||||
).run(debugger, print_completions=True)
|
).run(debugger, print_result=True)
|
||||||
else:
|
else:
|
||||||
for _ in range(int(arguments['--maxtries'])):
|
for _ in range(int(arguments['--maxtries'])):
|
||||||
t = TestCase.generate(arguments['<path>'] or '.')
|
t = TestCase.generate(arguments['<path>'] or '.')
|
||||||
|
|||||||
Reference in New Issue
Block a user