Show More
@@ -1050,6 +1050,7 b' class IPCompleter(Completer):' | |||||
1050 | self.matchers = [ |
|
1050 | self.matchers = [ | |
1051 | self.python_matches, |
|
1051 | self.python_matches, | |
1052 | self.file_matches, |
|
1052 | self.file_matches, | |
|
1053 | self.magic_config_matches, | |||
1053 | self.magic_matches, |
|
1054 | self.magic_matches, | |
1054 | self.python_func_kw_matches, |
|
1055 | self.python_func_kw_matches, | |
1055 | self.dict_key_matches, |
|
1056 | self.dict_key_matches, | |
@@ -1174,6 +1175,43 b' class IPCompleter(Completer):' | |||||
1174 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] |
|
1175 | comp += [ pre+m for m in line_magics if m.startswith(bare_text)] | |
1175 | return [cast_unicode_py2(c) for c in comp] |
|
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 | def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str): |
|
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 | lazy property) and can require some warm-up, more warm up than just |
|
1708 | lazy property) and can require some warm-up, more warm up than just | |
1671 | computing the ``name`` of a completion. The warm-up can be : |
|
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 | install/update: actually build parse/inference tree. |
|
1712 | install/update: actually build parse/inference tree. | |
1675 |
|
1713 | |||
1676 | - first time the module is encountered in a session: load tree from |
|
1714 | - first time the module is encountered in a session: load tree from |
@@ -576,6 +576,35 b' def test_magic_completion_order():' | |||||
576 | text, matches = c.complete('timeit') |
|
576 | text, matches = c.complete('timeit') | |
577 | nt.assert_equal(matches, ["timeit", "%timeit", "%%timeit"]) |
|
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 | def test_match_dict_keys(): |
|
608 | def test_match_dict_keys(): | |
580 | """ |
|
609 | """ | |
581 | Test that match_dict_keys works on a couple of use case does return what |
|
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