##// END OF EJS Templates
Ensure set_custom_completer is working. Fixes #11272
Nathan Goldbaum -
Show More
@@ -626,6 +626,8 b' class Completer(Configurable):'
626 626 else:
627 627 self.global_namespace = global_namespace
628 628
629 self.custom_matchers = []
630
629 631 super(Completer, self).__init__(**kwargs)
630 632
631 633 def complete(self, text, state):
@@ -1122,12 +1124,14 b' class IPCompleter(Completer):'
1122 1124
1123 1125 if self.use_jedi:
1124 1126 return [
1127 *self.custom_matchers,
1125 1128 self.file_matches,
1126 1129 self.magic_matches,
1127 1130 self.dict_key_matches,
1128 1131 ]
1129 1132 else:
1130 1133 return [
1134 *self.custom_matchers,
1131 1135 self.python_matches,
1132 1136 self.file_matches,
1133 1137 self.magic_matches,
@@ -2218,7 +2218,7 b' class InteractiveShell(SingletonConfigurable):'
2218 2218 list where you want the completer to be inserted."""
2219 2219
2220 2220 newcomp = types.MethodType(completer,self.Completer)
2221 self.Completer.matchers.insert(pos,newcomp)
2221 self.Completer.custom_matchers.insert(pos,newcomp)
2222 2222
2223 2223 def set_completer_frame(self, frame=None):
2224 2224 """Set the frame of the completer."""
@@ -998,3 +998,21 b' def test_should_run_async():'
998 998 assert not ip.should_run_async("a = 5")
999 999 assert ip.should_run_async("await x")
1000 1000 assert ip.should_run_async("import asyncio; await asyncio.sleep(1)")
1001
1002
1003 def test_set_custom_completer():
1004 num_completers = len(ip.Completer.matchers)
1005
1006 def foo(*args, **kwargs):
1007 return "I'm a completer!"
1008
1009 ip.set_custom_completer(foo, 0)
1010
1011 # check that we've really added a new completer
1012 assert len(ip.Completer.matchers) == num_completers + 1
1013
1014 # check that the first completer is the function we defined
1015 assert ip.Completer.matchers[0]() == "I'm a completer!"
1016
1017 # clean up
1018 ip.Completer.custom_matchers.pop()
General Comments 0
You need to be logged in to leave comments. Login now