Show More
@@ -1337,7 +1337,8 b' class IPCompleter(Completer):' | |||
|
1337 | 1337 | ) |
|
1338 | 1338 | |
|
1339 | 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 | 1342 | help=""" |
|
1342 | 1343 | Whether to suppress completions from other *Matchers*. |
|
1343 | 1344 | |
@@ -2703,13 +2704,14 b' class IPCompleter(Completer):' | |||
|
2703 | 2704 | if not suppressed_matchers: |
|
2704 | 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 | 2712 | should_suppress = ( |
|
2707 |
|
|
|
2708 | or suppression_recommended | |
|
2709 | or ( | |
|
2710 | isinstance(self.suppress_competing_matchers, dict) | |
|
2711 | and self.suppress_competing_matchers[matcher_id] | |
|
2712 | ) | |
|
2713 | (suppression_config is True) | |
|
2714 | or (suppression_recommended and (suppression_config is not False)) | |
|
2713 | 2715 | ) and len(result["completions"]) |
|
2714 | 2716 | |
|
2715 | 2717 | if should_suppress: |
@@ -139,7 +139,7 b' class ConfigMagics(Magics):' | |||
|
139 | 139 | ``IPCompleter.merge_completions`` and can be beneficial for performance, but |
|
140 | 140 | will sometimes omit relevant candidates from matchers further down the |
|
141 | 141 | priority list. |
|
142 |
Current: |
|
|
142 | Current: None | |
|
143 | 143 | IPCompleter.use_jedi=<Bool> |
|
144 | 144 | Experimental: Use Jedi to generate autocompletions. Default to True if jedi |
|
145 | 145 | is installed. |
@@ -1295,6 +1295,36 b' class TestCompleter(unittest.TestCase):' | |||
|
1295 | 1295 | for c in completions: |
|
1296 | 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 | 1328 | def test_matcher_suppression(self): |
|
1299 | 1329 | @completion_matcher(identifier="a_matcher") |
|
1300 | 1330 | def a_matcher(text): |
@@ -1326,16 +1356,34 b' class TestCompleter(unittest.TestCase):' | |||
|
1326 | 1356 | c = ip.Completer |
|
1327 | 1357 | |
|
1328 | 1358 | def _(text, expected): |
|
1329 | with provisionalcompleter(): | |
|
1330 | c.use_jedi = False | |
|
1331 | s, matches = c.complete(text) | |
|
1332 | self.assertEqual(expected, matches) | |
|
1359 | c.use_jedi = False | |
|
1360 | s, matches = c.complete(text) | |
|
1361 | self.assertEqual(expected, matches) | |
|
1333 | 1362 | |
|
1334 | 1363 | _("do not suppress", ["completion_a", "completion_b", "completion_c"]) |
|
1335 | 1364 | _("suppress all", ["completion_b"]) |
|
1336 | 1365 | _("suppress all but a", ["completion_a", "completion_b"]) |
|
1337 | 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 | 1387 | def test_matcher_disabling(self): |
|
1340 | 1388 | @completion_matcher(identifier="a_matcher") |
|
1341 | 1389 | def a_matcher(text): |
@@ -1346,10 +1394,8 b' class TestCompleter(unittest.TestCase):' | |||
|
1346 | 1394 | return ["completion_b"] |
|
1347 | 1395 | |
|
1348 | 1396 | def _(expected): |
|
1349 | with provisionalcompleter(): | |
|
1350 | c.use_jedi = False | |
|
1351 | s, matches = c.complete("completion_") | |
|
1352 | self.assertEqual(expected, matches) | |
|
1397 | s, matches = c.complete("completion_") | |
|
1398 | self.assertEqual(expected, matches) | |
|
1353 | 1399 | |
|
1354 | 1400 | with custom_matchers([a_matcher, b_matcher]): |
|
1355 | 1401 | ip = get_ipython() |
@@ -1376,10 +1422,8 b' class TestCompleter(unittest.TestCase):' | |||
|
1376 | 1422 | return {"completions": [SimpleCompletion("completion_b")], "suppress": True} |
|
1377 | 1423 | |
|
1378 | 1424 | def _(expected): |
|
1379 | with provisionalcompleter(): | |
|
1380 | c.use_jedi = False | |
|
1381 | s, matches = c.complete("completion_") | |
|
1382 | self.assertEqual(expected, matches) | |
|
1425 | s, matches = c.complete("completion_") | |
|
1426 | self.assertEqual(expected, matches) | |
|
1383 | 1427 | |
|
1384 | 1428 | with custom_matchers([a_matcher, b_matcher]): |
|
1385 | 1429 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now