Skip to content

Commit

Permalink
Merge pull request ipython#13483 from ygeyzel/master
Browse files Browse the repository at this point in the history
Typing '%' restrict autocompletion to magics
  • Loading branch information
Carreau authored Feb 25, 2022
2 parents fee5dbb + f6e3393 commit 04b271c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2139,8 +2139,9 @@ def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
# different types of objects. The rlcomplete() method could then
# simply collapse the dict into a list for readline, but we'd have
# richer completion semantics in other environments.
completions:Iterable[Any] = []
if self.use_jedi:
is_magic_prefix = len(text) > 0 and text[0] == "%"
completions: Iterable[Any] = []
if self.use_jedi and not is_magic_prefix:
if not full_text:
full_text = line_buffer
completions = self._jedi_matches(
Expand Down
11 changes: 11 additions & 0 deletions IPython/core/tests/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,3 +1262,14 @@ def meth_2(self, meth2_arg1, meth2_arg2):
_, matches = ip.complete(None, "test.meth(")
self.assertIn("meth_arg1=", matches)
self.assertNotIn("meth2_arg1=", matches)

def test_percent_symbol_restrict_to_magic_completions(self):
ip = get_ipython()
completer = ip.Completer
text = "%a"

with provisionalcompleter():
completer.use_jedi = True
completions = completer.completions(text, len(text))
for c in completions:
self.assertEqual(c.text[0], "%")

0 comments on commit 04b271c

Please sign in to comment.