forked from VimPlug/jedi
change debug functions for jedi-vim
This commit is contained in:
@@ -67,6 +67,7 @@ class Script(object):
|
||||
"""
|
||||
def __init__(self, source, line, column, source_path,
|
||||
source_encoding='utf-8'):
|
||||
debug.reset_time()
|
||||
try:
|
||||
source = unicode(source, source_encoding, 'replace')
|
||||
# Use 'replace' over 'ignore' to hold code structure.
|
||||
@@ -76,7 +77,7 @@ class Script(object):
|
||||
self.module = modules.ModuleWithCursor(source_path, source=source,
|
||||
position=self.pos)
|
||||
self.source_path = source_path
|
||||
debug.reset_time()
|
||||
debug.speed('init')
|
||||
|
||||
@property
|
||||
def parser(self):
|
||||
@@ -406,3 +407,6 @@ def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
|
||||
:param func_cb: The callback function for debug messages, with n params.
|
||||
"""
|
||||
debug.debug_function = func_cb
|
||||
debug.enable_warning = warnings
|
||||
debug.enable_notice = notices
|
||||
debug.enable_speed = speed
|
||||
|
||||
@@ -20,6 +20,7 @@ enable_speed = False
|
||||
enable_warning = False
|
||||
enable_notice = False
|
||||
|
||||
# callback, interface: level, str
|
||||
debug_function = None
|
||||
ignored_modules = ['parsing', 'builtin', 'jedi.builtin', 'jedi.parsing']
|
||||
|
||||
@@ -35,29 +36,29 @@ def dbg(*args):
|
||||
frm = inspect.stack()[1]
|
||||
mod = inspect.getmodule(frm[0])
|
||||
if not (mod.__name__ in ignored_modules):
|
||||
debug_function(NOTICE, *args)
|
||||
debug_function(NOTICE, 'dbg: ' + ', '.join(str(a) for a in args))
|
||||
|
||||
|
||||
def warning(*args):
|
||||
if debug_function and enable_warning:
|
||||
debug_function(WARNING, *args)
|
||||
debug_function(WARNING, 'warning: ' + ', '.join(str(a) for a in args))
|
||||
|
||||
|
||||
def speed(name):
|
||||
if debug_function:
|
||||
args = ('%s\t\t' % name,)
|
||||
debug_function(SPEED, *args)
|
||||
if debug_function and enable_speed:
|
||||
now = time.time()
|
||||
debug_function(SPEED, 'speed: ' + '%s %s' % (name, now - start_time))
|
||||
|
||||
|
||||
def print_to_stdout(level, *args):
|
||||
def print_to_stdout(level, str_out):
|
||||
""" The default debug function """
|
||||
if level == NOTICE:
|
||||
msg = Fore.GREEN + 'dbg: '
|
||||
col = Fore.GREEN
|
||||
elif level == WARNING:
|
||||
msg = Fore.RED + 'warning: '
|
||||
col = Fore.RED
|
||||
else:
|
||||
msg = Fore.YELLOW + 'speed: '
|
||||
print(msg + ', '.join(str(a) for a in args) + Fore.RESET)
|
||||
col = Fore.YELLOW
|
||||
print(col + str_out + Fore.RESET)
|
||||
|
||||
|
||||
#debug_function = print_to_stdout
|
||||
|
||||
Reference in New Issue
Block a user