Show More
@@ -43,6 +43,11 b' def _elide(string, *, min_elide=30):' | |||||
43 | return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(parts[0], parts[1][0], parts[-2][-1], parts[-1]) |
|
43 | return '{}.{}\N{HORIZONTAL ELLIPSIS}{}.{}'.format(parts[0], parts[1][0], parts[-2][-1], parts[-1]) | |
44 |
|
44 | |||
45 |
|
45 | |||
|
46 | def _adjust_completion_text_based_on_context(text, body, offset): | |||
|
47 | if text.endswith('=') and len(body) > offset and body[offset] is '=': | |||
|
48 | return text[:-1] | |||
|
49 | else: | |||
|
50 | return text | |||
46 |
|
51 | |||
47 |
|
52 | |||
48 | class IPythonPTCompleter(Completer): |
|
53 | class IPythonPTCompleter(Completer): | |
@@ -113,10 +118,11 b' class IPythonPTCompleter(Completer):' | |||||
113 | # display_meta=meta_text) |
|
118 | # display_meta=meta_text) | |
114 | display_text = c.text |
|
119 | display_text = c.text | |
115 |
|
120 | |||
|
121 | adjusted_text = _adjust_completion_text_based_on_context(c.text, body, offset) | |||
116 | if c.type == 'function': |
|
122 | if c.type == 'function': | |
117 | display_text = display_text + '()' |
|
123 | display_text = display_text + '()' | |
118 |
|
124 | |||
119 |
yield Completion( |
|
125 | yield Completion(adjusted_text, start_position=c.start - offset, display=_elide(display_text), display_meta=c.type) | |
120 |
|
126 | |||
121 | class IPythonPTLexer(Lexer): |
|
127 | class IPythonPTLexer(Lexer): | |
122 | """ |
|
128 | """ |
@@ -10,7 +10,7 b' from IPython.core.inputtransformer import InputTransformer' | |||||
10 | from IPython.testing import tools as tt |
|
10 | from IPython.testing import tools as tt | |
11 | from IPython.utils.capture import capture_output |
|
11 | from IPython.utils.capture import capture_output | |
12 |
|
12 | |||
13 | from IPython.terminal.ptutils import _elide |
|
13 | from IPython.terminal.ptutils import _elide, _adjust_completion_text_based_on_context | |
14 | import nose.tools as nt |
|
14 | import nose.tools as nt | |
15 |
|
15 | |||
16 | class TestElide(unittest.TestCase): |
|
16 | class TestElide(unittest.TestCase): | |
@@ -20,6 +20,19 b' class TestElide(unittest.TestCase):' | |||||
20 | _elide('concatenate((a1, a2, ..), . axis') # do not raise |
|
20 | _elide('concatenate((a1, a2, ..), . axis') # do not raise | |
21 | nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh'), 'aaaa.b…g.hhhhhh') |
|
21 | nt.assert_equal(_elide('aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhh'), 'aaaa.b…g.hhhhhh') | |
22 |
|
22 | |||
|
23 | ||||
|
24 | class TestContextAwareCompletion(unittest.TestCase): | |||
|
25 | ||||
|
26 | def test_adjust_completion_text_based_on_context(self): | |||
|
27 | # Adjusted case | |||
|
28 | nt.assert_equal(_adjust_completion_text_based_on_context('arg1=', 'func1(a=)', 7), 'arg1') | |||
|
29 | ||||
|
30 | # Untouched cases | |||
|
31 | nt.assert_equal(_adjust_completion_text_based_on_context('arg1=', 'func1(a)', 7), 'arg1=') | |||
|
32 | nt.assert_equal(_adjust_completion_text_based_on_context('arg1=', 'func1(a', 7), 'arg1=') | |||
|
33 | nt.assert_equal(_adjust_completion_text_based_on_context('%magic', 'func1(a=)', 7), '%magic') | |||
|
34 | nt.assert_equal(_adjust_completion_text_based_on_context('func2', 'func1(a=)', 7), 'func2') | |||
|
35 | ||||
23 | # Decorator for interaction loop tests ----------------------------------------- |
|
36 | # Decorator for interaction loop tests ----------------------------------------- | |
24 |
|
37 | |||
25 | class mock_input_helper(object): |
|
38 | class mock_input_helper(object): |
General Comments 0
You need to be logged in to leave comments.
Login now