1
0
forked from VimPlug/jedi

Make it possible to debug the REPL.

This commit is contained in:
Dave Halter
2016-08-02 23:07:47 +02:00
parent 05ad8c6608
commit 7c5e75f31b
2 changed files with 18 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ Utilities for end-users.
from __future__ import absolute_import from __future__ import absolute_import
import __main__ import __main__
from collections import namedtuple from collections import namedtuple
import logging
import traceback
import re import re
import os import os
import sys import sys
@@ -14,6 +16,9 @@ from jedi.api.helpers import get_on_completion_name
from jedi import common from jedi import common
READLINE_DEBUG = False
def setup_readline(namespace_module=__main__): def setup_readline(namespace_module=__main__):
""" """
Install Jedi completer to :mod:`readline`. Install Jedi completer to :mod:`readline`.
@@ -55,6 +60,13 @@ def setup_readline(namespace_module=__main__):
bash). bash).
""" """
if READLINE_DEBUG:
logging.basicConfig(
filename='/tmp/jedi.log',
filemode='a',
level=logging.DEBUG
)
class JediRL(object): class JediRL(object):
def complete(self, text, state): def complete(self, text, state):
""" """
@@ -70,6 +82,7 @@ def setup_readline(namespace_module=__main__):
sys.path.insert(0, os.getcwd()) sys.path.insert(0, os.getcwd())
# Calling python doesn't have a path, so add to sys.path. # Calling python doesn't have a path, so add to sys.path.
try: try:
logging.debug("Start REPL completion: " + repr(text))
interpreter = Interpreter(text, [namespace_module.__dict__]) interpreter = Interpreter(text, [namespace_module.__dict__])
lines = common.splitlines(text) lines = common.splitlines(text)
@@ -77,6 +90,9 @@ def setup_readline(namespace_module=__main__):
name = get_on_completion_name(interpreter._get_module(), lines, position) name = get_on_completion_name(interpreter._get_module(), lines, position)
before = text[:len(text) - len(name)] before = text[:len(text) - len(name)]
completions = interpreter.completions() completions = interpreter.completions()
except:
logging.error("REPL Completion error:\n" + traceback.format_exc())
raise
finally: finally:
sys.path.pop(0) sys.path.pop(0)

View File

@@ -156,4 +156,5 @@ class TestInterpreterAPI(TestCase):
lambd = lambda x: 3 lambd = lambda x: 3
self.check_interpreter_complete('foo(bar', locals(), ['bar']) self.check_interpreter_complete('foo(bar', locals(), ['bar'])
self.check_interpreter_complete('lambd(x', locals(), ['x']) # TODO we're not yet using the Python3.5 inspect.signature, yet.
assert not jedi.Interpreter('lambd(x', [locals()]).completions()