MCPcopy Create free account
hub / github.com/ipython/ipython / _complete

Method _complete

IPython/core/completer.py:1958–2069  ·  view source on GitHub ↗

Like complete but can also returns raw jedi completions as well as the origin of the completion text. This could (and should) be made much cleaner but that will be simpler once we drop the old (and stateful) :any:`complete` API. With current provisional AP

(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
                  full_text=None)

Source from the content-addressed store, hash-verified

1956 return self._complete(line_buffer=line_buffer, cursor_pos=cursor_pos, text=text, cursor_line=0)[:2]
1957
1958 def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
1959 full_text=None) -> Tuple[str, List[str], List[str], Iterable[_FakeJediCompletion]]:
1960 """
1961
1962 Like complete but can also returns raw jedi completions as well as the
1963 origin of the completion text. This could (and should) be made much
1964 cleaner but that will be simpler once we drop the old (and stateful)
1965 :any:`complete` API.
1966
1967
1968 With current provisional API, cursor_pos act both (depending on the
1969 caller) as the offset in the ``text`` or ``line_buffer``, or as the
1970 ``column`` when passing multiline strings this could/should be renamed
1971 but would add extra noise.
1972 """
1973
1974 # if the cursor position isn't given, the only sane assumption we can
1975 # make is that it's at the end of the line (the common case)
1976 if cursor_pos is None:
1977 cursor_pos = len(line_buffer) if text is None else len(text)
1978
1979 if self.use_main_ns:
1980 self.namespace = __main__.__dict__
1981
1982 # if text is either None or an empty string, rely on the line buffer
1983 if (not line_buffer) and full_text:
1984 line_buffer = full_text.split('\n')[cursor_line]
1985 if not text: # issue #11508: check line_buffer before calling split_line
1986 text = self.splitter.split_line(line_buffer, cursor_pos) if line_buffer else ''
1987
1988 if self.backslash_combining_completions:
1989 # allow deactivation of these on windows.
1990 base_text = text if not line_buffer else line_buffer[:cursor_pos]
1991 latex_text, latex_matches = self.latex_matches(base_text)
1992 if latex_matches:
1993 return latex_text, latex_matches, ['latex_matches']*len(latex_matches), ()
1994 name_text = ''
1995 name_matches = []
1996 # need to add self.fwd_unicode_match() function here when done
1997 for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches, self.fwd_unicode_match):
1998 name_text, name_matches = meth(base_text)
1999 if name_text:
2000 return name_text, name_matches[:MATCHES_LIMIT], \
2001 [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), ()
2002
2003
2004 # If no line buffer is given, assume the input text is all there was
2005 if line_buffer is None:
2006 line_buffer = text
2007
2008 self.line_buffer = line_buffer
2009 self.text_until_cursor = self.line_buffer[:cursor_pos]
2010
2011 # Do magic arg matches
2012 for matcher in self.magic_arg_matchers:
2013 matches = list(matcher(line_buffer))[:MATCHES_LIMIT]
2014 if matches:
2015 origins = [matcher.__qualname__] * len(matches)

Callers 3

_completionsMethod · 0.95
completeMethod · 0.95

Calls 7

latex_matchesMethod · 0.95
_jedi_matchesMethod · 0.95
completions_sorting_keyFunction · 0.85
split_lineMethod · 0.80
excepthookMethod · 0.45
addMethod · 0.45

Tested by 1