mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Make it possible to debug the REPL.
This commit is contained in:
@@ -5,6 +5,8 @@ Utilities for end-users.
|
||||
from __future__ import absolute_import
|
||||
import __main__
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import traceback
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
@@ -14,6 +16,9 @@ from jedi.api.helpers import get_on_completion_name
|
||||
from jedi import common
|
||||
|
||||
|
||||
READLINE_DEBUG = False
|
||||
|
||||
|
||||
def setup_readline(namespace_module=__main__):
|
||||
"""
|
||||
Install Jedi completer to :mod:`readline`.
|
||||
@@ -55,6 +60,13 @@ def setup_readline(namespace_module=__main__):
|
||||
bash).
|
||||
|
||||
"""
|
||||
if READLINE_DEBUG:
|
||||
logging.basicConfig(
|
||||
filename='/tmp/jedi.log',
|
||||
filemode='a',
|
||||
level=logging.DEBUG
|
||||
)
|
||||
|
||||
class JediRL(object):
|
||||
def complete(self, text, state):
|
||||
"""
|
||||
@@ -70,6 +82,7 @@ def setup_readline(namespace_module=__main__):
|
||||
sys.path.insert(0, os.getcwd())
|
||||
# Calling python doesn't have a path, so add to sys.path.
|
||||
try:
|
||||
logging.debug("Start REPL completion: " + repr(text))
|
||||
interpreter = Interpreter(text, [namespace_module.__dict__])
|
||||
|
||||
lines = common.splitlines(text)
|
||||
@@ -77,6 +90,9 @@ def setup_readline(namespace_module=__main__):
|
||||
name = get_on_completion_name(interpreter._get_module(), lines, position)
|
||||
before = text[:len(text) - len(name)]
|
||||
completions = interpreter.completions()
|
||||
except:
|
||||
logging.error("REPL Completion error:\n" + traceback.format_exc())
|
||||
raise
|
||||
finally:
|
||||
sys.path.pop(0)
|
||||
|
||||
|
||||
@@ -156,4 +156,5 @@ class TestInterpreterAPI(TestCase):
|
||||
lambd = lambda x: 3
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user