def get_completions(self, info): '''Get Python completions''' # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py if jedi is None: return [] text = info['code'] position = (info['line_num'], info['column']) interpreter = Interpreter(text, [self.env]) if jedi.__version__ >= LooseVersion('0.12.0'): lines = split_lines(text) name = get_on_completion_name(interpreter._module_node, lines, position) before = text[:len(text) - len(name)] elif jedi.__version__ >= LooseVersion('0.10.0'): lines = split_lines(text) name = get_on_completion_name(interpreter._get_module_node(), lines, position) before = text[:len(text) - len(name)] else: path = UserContext(text, position).get_path_until_cursor() path, dot, like = completion_parts(path) before = text[:len(text) - len(like)] completions = interpreter.completions() completions = [before + c.name_with_symbols for c in completions] self.kernel.log.error(completions) return [c[info['start']:] for c in completions]
def get_completions(self, info): '''Get Python completions''' # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py if jedi is None: return [] text = info['code'] position = (info['line_num'], info['column']) interpreter = Interpreter(text, [self.env]) lines = split_lines(text) name = get_on_completion_name( interpreter._module_node, lines, position ) before = text[:len(text) - len(name)] try: completions = interpreter.complete() except AttributeError: completions = interpreter.completions() completions = [before + c.name_with_symbols for c in completions] self.kernel.log.error(completions) return [c[info['start']:] for c in completions]
def get_completions(self, info): """Gets Python completions based on the current cursor position within the %%init_spark cell. Based on https://github.com/Calysto/metakernel/blob/master/metakernel/magics/python_magic.py Parameters ---------- info : dict Information about the current caret position """ if jedi is None: return [] text = info['code'] position = (info['line_num'], info['column']) interpreter = jedi.Interpreter(text, [self.env]) lines = common.splitlines(text) name = get_on_completion_name(interpreter._get_module_node(), lines, position) before = text[:len(text) - len(name)] completions = interpreter.completions() completions = [before + c.name_with_symbols for c in completions] return [c[info['start']:] for c in completions]
def complete(self, text, state): """ This complete stuff is pretty weird, a generator would make a lot more sense, but probably due to backwards compatibility this is still the way how it works. The only important part is stuff in the ``state == 0`` flow, everything else has been copied from the ``rlcompleter`` std. library module. """ if state == 0: 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) position = (len(lines), len(lines[-1])) 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) self.matches = [before + c.name_with_symbols for c in completions] try: return self.matches[state] except IndexError: return None
def complete(self, text, state): """ This complete stuff is pretty weird, a generator would make a lot more sense, but probably due to backwards compatibility this is still the way how it works. The only important part is stuff in the ``state == 0`` flow, everything else has been copied from the ``rlcompleter`` std. library module. """ if state == 0: sys.path.insert(0, os.getcwd()) # Calling python doesn't have a path, so add to sys.path. try: interpreter = Interpreter(text, [namespace_module.__dict__]) lines = common.splitlines(text) position = (len(lines), len(lines[-1])) name = get_on_completion_name(lines, position) before = text[:len(text) - len(name)] completions = interpreter.completions() finally: sys.path.pop(0) self.matches = [ before + c.name_with_symbols for c in completions ] try: return self.matches[state] except IndexError: return None
def __init__(self, evaluator, module, code_lines, position, call_signatures_method): self._evaluator = evaluator self._module = evaluator.wrap(module) self._code_lines = code_lines # The first step of completions is to get the name self._like_name = helpers.get_on_completion_name(module, code_lines, position) # The actual cursor position is not what we need to calculate # everything. We want the start of the name we're on. self._position = position[0], position[1] - len(self._like_name) self._call_signatures_method = call_signatures_method
def __init__(self, evaluator, module, code_lines, position, call_signatures_method): self._evaluator = evaluator self._module = evaluator.wrap(module) self._code_lines = code_lines # The first step of completions is to get the name self._like_name = helpers.get_on_completion_name(code_lines, position) # The actual cursor position is not what we need to calculate # everything. We want the start of the name we're on. self._position = position[0], position[1] - len(self._like_name) self._call_signatures_method = call_signatures_method
def __init__(self, evaluator, module, code_lines, position, call_signatures_callback): self._evaluator = evaluator self._module_context = module self._module_node = module.tree_node self._code_lines = code_lines # The first step of completions is to get the name self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position) # The actual cursor position is not what we need to calculate # everything. We want the start of the name we're on. self._original_position = position self._position = position[0], position[1] - len(self._like_name) self._call_signatures_callback = call_signatures_callback
def get_completions(self, info): '''Get Python completions''' # https://github.com/davidhalter/jedi/blob/master/jedi/utils.py if jedi is None: return [] text = info['code'] position = (info['line_num'], info['column']) interpreter = Interpreter(text, [self.env]) if jedi.__version__ >= LooseVersion('0.12.0'): lines = split_lines(text) name = get_on_completion_name( interpreter._module_node, lines, position ) before = text[:len(text) - len(name)] elif jedi.__version__ >= LooseVersion('0.10.0'): lines = split_lines(text) name = get_on_completion_name( interpreter._get_module_node(), lines, position ) before = text[:len(text) - len(name)] else: path = UserContext(text, position).get_path_until_cursor() path, dot, like = completion_parts(path) before = text[:len(text) - len(like)] completions = interpreter.completions() completions = [before + c.name_with_symbols for c in completions] self.kernel.log.error(completions) return [c[info['start']:] for c in completions]
def __init__(self, inference_state, module_context, code_lines, position, signatures_callback, fuzzy=False): self._inference_state = inference_state self._module_context = module_context self._module_node = module_context.tree_node self._code_lines = code_lines # The first step of completions is to get the name self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position) # The actual cursor position is not what we need to calculate # everything. We want the start of the name we're on. self._original_position = position self._signatures_callback = signatures_callback self._fuzzy = fuzzy
def __init__(self, evaluator, module, code_lines, position, call_signatures_method): self._evaluator = evaluator self._module_context = module self._module_node = module.tree_node self._code_lines = code_lines # The first step of completions is to get the name self._like_name = helpers.get_on_completion_name(self._module_node, code_lines, position) # The actual cursor position is not what we need to calculate # everything. We want the start of the name we're on. # Some hacks to increase speed of Jedi current_line = self._code_lines[position[0] - 1] if '.' not in current_line and '(' not in current_line: init_speed_hacks(True) else: init_speed_hacks(False) self._position = position[0], position[1] - len(self._like_name) self._call_signatures_method = call_signatures_method