def get_completions(word, code, subcontext, cursor_indentation): """gets the completions for word after evaluating code""" global subprogram_globals parsed_subcontext = context.calculate_subcontext(subcontext, cursor_indentation) context.exec_code(code) keys = context.get_context() dots = word.split('.') # If it is a not completable python expression completions = an empty list pattern = "^[A-Za-z_][A-Za-z_0-9]*([.][A-Za-z_][A-Za-z_0-9]*)*\.?$" if not re.match(pattern, word): completions = [] elif word.rfind('.') == -1: # If the word is a simple statement not containing "." completions = # the global keys starting with the word completions = [i for i in keys if i.startswith(word)] else: if word.startswith('self'): dot_index = parsed_subcontext.rfind('.') parsed_subcontext = parsed_subcontext[:dot_index] word = word.replace('self', parsed_subcontext) # If word ends with a "." strip it and execute get_dir if word.endswith('.'): module = context.eval_code(word[:-1]) if module: completions = get_dir(module) else: completions = [] else: # If word does not ends with "." but it contains a dot # then eval word up to ".", split the remaining part, get # the attributes of the module when the attribute starts # with the remaining dot_index = word.rfind('.') module = context.eval_code(word[:dot_index]) if module: mword = word[dot_index + 1:] completions = [ i for i in get_dir(module) if i.startswith(mword) ] else: completions = [] return sorted(list(set(completions)))
def get_completions(word, code, subcontext, cursor_indentation): """gets the completions for word after evaluating code""" global subprogram_globals parsed_subcontext = context.calculate_subcontext(subcontext, cursor_indentation) context.exec_code(code) keys = context.get_context() dots = word.split('.') # If it is a not completable python expression completions = an empty list pattern = "^[A-Za-z_][A-Za-z_0-9]*([.][A-Za-z_][A-Za-z_0-9]*)*\.?$" if not re.match(pattern, word): completions = [] elif word.rfind('.') == -1: # If the word is a simple statement not containing "." completions = # the global keys starting with the word completions = [i for i in keys if i.startswith(word)] else: if word.startswith('self'): dot_index = parsed_subcontext.rfind('.') parsed_subcontext = parsed_subcontext[:dot_index] word = word.replace('self', parsed_subcontext) # If word ends with a "." strip it and execute get_dir if word.endswith('.'): module = context.eval_code(word[:-1]) if module: completions = get_dir(module) else: completions = [] else: # If word does not ends with "." but it contains a dot # then eval word up to ".", split the remaining part, get # the attributes of the module when the attribute starts # with the remaining dot_index = word.rfind('.') module = context.eval_code(word[:dot_index]) if module: mword = word[dot_index+1:] completions = [i for i in get_dir(module) if i.startswith(mword)] else: completions = [] return sorted(list(set(completions)))
def get_help(obj): """Returns the help of the given object. Inspired in the original pycomplete package """ paren = obj.rfind("(") if paren != -1: obj = obj[:paren] if obj.endswith("(") or obj.endswith("."): obj = obj[:-1] found = False pobj = None context_dict = 'subprogram_globals' if not obj in context.get_context(): context_dict = 'helper_globals' found = context.cimport(obj, context_dict) else: pobj = context.eval_code(obj) if obj not in context.subcontext_globals and found: pobj = context.eval_code(obj, context_dict) if not pobj: return "no help string for " + obj obj = context.eval_code(obj) return pydoc.getdoc(obj)
def get_signature(obj): """Returns the signature of the given object. Inspired in the original pycomplete package """ # FIXME - make this function less ugly paren = obj.find("(") if paren != -1: obj = obj[:paren] context_dict = 'subprogram_globals' if not obj in context.get_context(): context_dict = 'helper_globals' if not context.cimport(obj, context_dict): return "no signature for " + obj try: obj = context.eval_code(obj, context_dict) except: return "no signature for " + obj print "yesy" sig = "" # This part is extracted from the pycomplete.py file if type(obj) in (types.ClassType, types.TypeType): obj = _find_constructor(obj) elif type(obj) == types.MethodType: obj = obj.im_func if type(obj) in [types.FunctionType, types.LambdaType]: (args, varargs, varkw, defaults) = inspect.getargspec(obj) sig = ('%s: %s' % (obj.__name__, inspect.formatargspec(args, varargs, varkw, defaults))) doc = getattr(obj, '__doc__', '') if doc and not sig: doc = doc.lstrip() pos = doc.find('\n') if pos < 0 or pos > 70: pos = 70 sig = doc[:pos] return sig
def get_signature(obj): """Returns the signature of the given object. Inspired in the original pycomplete package """ # FIXME - make this function less ugly paren = obj.find("(") if paren != -1: obj = obj[:paren] context_dict = 'subprogram_globals' if not obj in context.get_context(): context_dict = 'helper_globals' if not context.cimport(obj, context_dict): return "no signature for " + obj try: obj = context.eval_code(obj, context_dict) except: return "no signature for " + obj sig = "" # This part is extracted from the pycomplete.py file if type(obj) in (types.ClassType, types.TypeType): obj = _find_constructor(obj) elif type(obj) == types.MethodType: obj = obj.im_func if type(obj) in [types.FunctionType, types.LambdaType]: (args, varargs, varkw, defaults) = inspect.getargspec(obj) sig = ('%s: %s' % (obj.__name__, inspect.formatargspec(args, varargs, varkw, defaults))) doc = getattr(obj, '__doc__', '') if doc and not sig: doc = doc.lstrip() pos = doc.find('\n') if pos < 0 or pos > 70: pos = 70 sig = doc[:pos] return sig