##// END OF EJS Templates
Correct suppression defaults, add a test for #13735
krassowski -
Show More
@@ -1337,7 +1337,8 b' class IPCompleter(Completer):'
1337 )
1337 )
1338
1338
1339 suppress_competing_matchers = UnionTrait(
1339 suppress_competing_matchers = UnionTrait(
1340 [Bool(), DictTrait(Bool(None, allow_none=True))],
1340 [Bool(allow_none=True), DictTrait(Bool(None, allow_none=True))],
1341 default_value=None,
1341 help="""
1342 help="""
1342 Whether to suppress completions from other *Matchers*.
1343 Whether to suppress completions from other *Matchers*.
1343
1344
@@ -2703,13 +2704,14 b' class IPCompleter(Completer):'
2703 if not suppressed_matchers:
2704 if not suppressed_matchers:
2704 suppression_recommended = result.get("suppress", False)
2705 suppression_recommended = result.get("suppress", False)
2705
2706
2707 suppression_config = (
2708 self.suppress_competing_matchers.get(matcher_id, None)
2709 if isinstance(self.suppress_competing_matchers, dict)
2710 else self.suppress_competing_matchers
2711 )
2706 should_suppress = (
2712 should_suppress = (
2707 self.suppress_competing_matchers is True
2713 (suppression_config is True)
2708 or suppression_recommended
2714 or (suppression_recommended and (suppression_config is not False))
2709 or (
2710 isinstance(self.suppress_competing_matchers, dict)
2711 and self.suppress_competing_matchers[matcher_id]
2712 )
2713 ) and len(result["completions"])
2715 ) and len(result["completions"])
2714
2716
2715 if should_suppress:
2717 if should_suppress:
@@ -139,7 +139,7 b' class ConfigMagics(Magics):'
139 ``IPCompleter.merge_completions`` and can be beneficial for performance, but
139 ``IPCompleter.merge_completions`` and can be beneficial for performance, but
140 will sometimes omit relevant candidates from matchers further down the
140 will sometimes omit relevant candidates from matchers further down the
141 priority list.
141 priority list.
142 Current: False
142 Current: None
143 IPCompleter.use_jedi=<Bool>
143 IPCompleter.use_jedi=<Bool>
144 Experimental: Use Jedi to generate autocompletions. Default to True if jedi
144 Experimental: Use Jedi to generate autocompletions. Default to True if jedi
145 is installed.
145 is installed.
@@ -1295,6 +1295,36 b' class TestCompleter(unittest.TestCase):'
1295 for c in completions:
1295 for c in completions:
1296 self.assertEqual(c.text[0], "%")
1296 self.assertEqual(c.text[0], "%")
1297
1297
1298 def test_dict_key_restrict_to_dicts(self):
1299 """Test that dict key suppresses non-dict completion items"""
1300 ip = get_ipython()
1301 c = ip.Completer
1302 d = {"abc": None}
1303 ip.user_ns["d"] = d
1304
1305 text = 'd["a'
1306
1307 def _():
1308 with provisionalcompleter():
1309 c.use_jedi = True
1310 return [
1311 completion.text for completion in c.completions(text, len(text))
1312 ]
1313
1314 completions = _()
1315 self.assertEqual(completions, ["abc"])
1316
1317 # check that it can be disabled in granular manner:
1318 cfg = Config()
1319 cfg.IPCompleter.suppress_competing_matchers = {
1320 "IPCompleter.dict_key_matcher": False
1321 }
1322 c.update_config(cfg)
1323
1324 completions = _()
1325 self.assertIn("abc", completions)
1326 self.assertGreater(len(completions), 1)
1327
1298 def test_matcher_suppression(self):
1328 def test_matcher_suppression(self):
1299 @completion_matcher(identifier="a_matcher")
1329 @completion_matcher(identifier="a_matcher")
1300 def a_matcher(text):
1330 def a_matcher(text):
@@ -1326,16 +1356,34 b' class TestCompleter(unittest.TestCase):'
1326 c = ip.Completer
1356 c = ip.Completer
1327
1357
1328 def _(text, expected):
1358 def _(text, expected):
1329 with provisionalcompleter():
1359 c.use_jedi = False
1330 c.use_jedi = False
1360 s, matches = c.complete(text)
1331 s, matches = c.complete(text)
1361 self.assertEqual(expected, matches)
1332 self.assertEqual(expected, matches)
1333
1362
1334 _("do not suppress", ["completion_a", "completion_b", "completion_c"])
1363 _("do not suppress", ["completion_a", "completion_b", "completion_c"])
1335 _("suppress all", ["completion_b"])
1364 _("suppress all", ["completion_b"])
1336 _("suppress all but a", ["completion_a", "completion_b"])
1365 _("suppress all but a", ["completion_a", "completion_b"])
1337 _("suppress all but c", ["completion_b", "completion_c"])
1366 _("suppress all but c", ["completion_b", "completion_c"])
1338
1367
1368 def configure(suppression_config):
1369 cfg = Config()
1370 cfg.IPCompleter.suppress_competing_matchers = suppression_config
1371 c.update_config(cfg)
1372
1373 # test that configuration takes priority over the run-time decisions
1374
1375 configure(False)
1376 _("suppress all", ["completion_a", "completion_b", "completion_c"])
1377
1378 configure({"b_matcher": False})
1379 _("suppress all", ["completion_a", "completion_b", "completion_c"])
1380
1381 configure({"a_matcher": False})
1382 _("suppress all", ["completion_b"])
1383
1384 configure({"b_matcher": True})
1385 _("do not suppress", ["completion_b"])
1386
1339 def test_matcher_disabling(self):
1387 def test_matcher_disabling(self):
1340 @completion_matcher(identifier="a_matcher")
1388 @completion_matcher(identifier="a_matcher")
1341 def a_matcher(text):
1389 def a_matcher(text):
@@ -1346,10 +1394,8 b' class TestCompleter(unittest.TestCase):'
1346 return ["completion_b"]
1394 return ["completion_b"]
1347
1395
1348 def _(expected):
1396 def _(expected):
1349 with provisionalcompleter():
1397 s, matches = c.complete("completion_")
1350 c.use_jedi = False
1398 self.assertEqual(expected, matches)
1351 s, matches = c.complete("completion_")
1352 self.assertEqual(expected, matches)
1353
1399
1354 with custom_matchers([a_matcher, b_matcher]):
1400 with custom_matchers([a_matcher, b_matcher]):
1355 ip = get_ipython()
1401 ip = get_ipython()
@@ -1376,10 +1422,8 b' class TestCompleter(unittest.TestCase):'
1376 return {"completions": [SimpleCompletion("completion_b")], "suppress": True}
1422 return {"completions": [SimpleCompletion("completion_b")], "suppress": True}
1377
1423
1378 def _(expected):
1424 def _(expected):
1379 with provisionalcompleter():
1425 s, matches = c.complete("completion_")
1380 c.use_jedi = False
1426 self.assertEqual(expected, matches)
1381 s, matches = c.complete("completion_")
1382 self.assertEqual(expected, matches)
1383
1427
1384 with custom_matchers([a_matcher, b_matcher]):
1428 with custom_matchers([a_matcher, b_matcher]):
1385 ip = get_ipython()
1429 ip = get_ipython()
General Comments 0
You need to be logged in to leave comments. Login now