Show More
@@ -1050,6 +1050,7 b' class IPCompleter(Completer):' | |||
|
1050 | 1050 | self.matchers = [ |
|
1051 | 1051 | self.python_matches, |
|
1052 | 1052 | self.file_matches, |
|
1053 | self.magic_config_matches, | |
|
1053 | 1054 | self.magic_matches, |
|
1054 | 1055 | self.python_func_kw_matches, |
|
1055 | 1056 | self.dict_key_matches, |
@@ -1174,6 +1175,43 b' class IPCompleter(Completer):' | |||
|
1174 | 1175 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] |
|
1175 | 1176 | return [cast_unicode_py2(c) for c in comp] |
|
1176 | 1177 | |
|
1178 | def magic_config_matches(self, text): | |
|
1179 | """ Match class names and attributes for %config magic """ | |
|
1180 | # use line buffer instead of text (which is a word) | |
|
1181 | texts = self.line_buffer.strip().split() | |
|
1182 | ||
|
1183 | if len(texts) > 0 and \ | |
|
1184 | ('config'.startswith(texts[0]) or '%config'.startswith(texts[0])): | |
|
1185 | # get all configuration classes | |
|
1186 | classes = sorted(set([ c for c in self.shell.configurables | |
|
1187 | if c.__class__.class_traits(config=True) | |
|
1188 | ]), key=lambda x: x.__class__.__name__) | |
|
1189 | classnames = [ c.__class__.__name__ for c in classes ] | |
|
1190 | ||
|
1191 | # return all classnames if config or %config is given | |
|
1192 | if len(texts) == 1: | |
|
1193 | return classnames | |
|
1194 | ||
|
1195 | # match classname | |
|
1196 | classname_texts = texts[1].split('.') | |
|
1197 | classname = classname_texts[0] | |
|
1198 | classname_matches = [ c for c in classnames | |
|
1199 | if c.startswith(classname) ] | |
|
1200 | ||
|
1201 | # return matched classes or the matched class with attributes | |
|
1202 | if texts[1].find('.') < 0: | |
|
1203 | return classname_matches | |
|
1204 | elif len(classname_matches) == 1 and \ | |
|
1205 | classname_matches[0] == classname: | |
|
1206 | cls = classes[classnames.index(classname)].__class__ | |
|
1207 | help = cls.class_get_help() | |
|
1208 | # strip leading '--' from cl-args: | |
|
1209 | help = re.sub(re.compile(r'^--', re.MULTILINE), '', help) | |
|
1210 | return [ attr.split('=')[0] | |
|
1211 | for attr in help.strip().splitlines() | |
|
1212 | if attr.startswith(texts[1]) ] | |
|
1213 | return [] | |
|
1214 | ||
|
1177 | 1215 | def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str): |
|
1178 | 1216 | """ |
|
1179 | 1217 | |
@@ -1670,7 +1708,7 b' class IPCompleter(Completer):' | |||
|
1670 | 1708 | lazy property) and can require some warm-up, more warm up than just |
|
1671 | 1709 | computing the ``name`` of a completion. The warm-up can be : |
|
1672 | 1710 | |
|
1673 |
- Long warm-up the fi |
|
|
1711 | - Long warm-up the first time a module is encountered after | |
|
1674 | 1712 | install/update: actually build parse/inference tree. |
|
1675 | 1713 | |
|
1676 | 1714 | - first time the module is encountered in a session: load tree from |
@@ -576,6 +576,35 b' def test_magic_completion_order():' | |||
|
576 | 576 | text, matches = c.complete('timeit') |
|
577 | 577 | nt.assert_equal(matches, ["timeit", "%timeit", "%%timeit"]) |
|
578 | 578 | |
|
579 | ||
|
580 | def test_magic_config(): | |
|
581 | ip = get_ipython() | |
|
582 | c = ip.Completer | |
|
583 | ||
|
584 | s, matches = c.complete(None, 'conf') | |
|
585 | nt.assert_in('%config', matches) | |
|
586 | s, matches = c.complete(None, 'config ') | |
|
587 | nt.assert_in('AliasManager', matches) | |
|
588 | s, matches = c.complete(None, '%config ') | |
|
589 | nt.assert_in('AliasManager', matches) | |
|
590 | s, matches = c.complete(None, 'config Ali') | |
|
591 | nt.assert_in('AliasManager', matches) | |
|
592 | s, matches = c.complete(None, '%config Ali') | |
|
593 | nt.assert_in('AliasManager', matches) | |
|
594 | s, matches = c.complete(None, 'config AliasManager') | |
|
595 | nt.assert_list_equal(['AliasManager'], matches) | |
|
596 | s, matches = c.complete(None, '%config AliasManager') | |
|
597 | nt.assert_list_equal(['AliasManager'], matches) | |
|
598 | s, matches = c.complete(None, 'config AliasManager.') | |
|
599 | nt.assert_in('AliasManager.default_aliases', matches) | |
|
600 | s, matches = c.complete(None, '%config AliasManager.') | |
|
601 | nt.assert_in('AliasManager.default_aliases', matches) | |
|
602 | s, matches = c.complete(None, 'config AliasManager.de') | |
|
603 | nt.assert_in('AliasManager.default_aliases', matches) | |
|
604 | s, matches = c.complete(None, 'config AliasManager.de') | |
|
605 | nt.assert_in('AliasManager.default_aliases', matches) | |
|
606 | ||
|
607 | ||
|
579 | 608 | def test_match_dict_keys(): |
|
580 | 609 | """ |
|
581 | 610 | Test that match_dict_keys works on a couple of use case does return what |
General Comments 0
You need to be logged in to leave comments.
Login now