@@ -66,6 +66,37 @@ def julia(self, line, cell=None):
66
66
return ans
67
67
68
68
69
+ def julia_completer (self , event ):
70
+ pos = event .line .find ("%julia" )
71
+ if pos < 0 :
72
+ return []
73
+ pos += len ("%julia" ) # pos: beginning of Julia code
74
+ julia_code = event .line [pos :]
75
+ julia_pos = len (event .text_until_cursor ) - pos
76
+
77
+ julia = Julia ()
78
+ completions = julia .eval ("""
79
+ import REPL
80
+ (string, pos) -> begin
81
+ ret, _, should_complete =
82
+ REPL.completions(string, pos)
83
+ if should_complete
84
+ return map(REPL.completion_text, ret)
85
+ else
86
+ return String[]
87
+ end
88
+ end
89
+ """ )(julia_code , julia_pos )
90
+
91
+ if "." in event .symbol :
92
+ # When completing (say) "Base.s" we need to add the prefix "Base."
93
+ prefix = event .symbol .rsplit ("." , 1 )[0 ]
94
+ completions = ["." .join ((prefix , c )) for c in completions ]
95
+ return completions
96
+ # See:
97
+ # IPython.core.completer.dispatch_custom_completer
98
+
99
+
69
100
# Add to the global docstring the class information.
70
101
__doc__ = __doc__ .format (
71
102
JULIAMAGICS_DOC = ' ' * 8 + JuliaMagics .__doc__ ,
@@ -80,3 +111,9 @@ def julia(self, line, cell=None):
80
111
def load_ipython_extension (ip ):
81
112
"""Load the extension in IPython."""
82
113
ip .register_magics (JuliaMagics )
114
+ ip .set_hook ("complete_command" , julia_completer ,
115
+ re_key = "%?%julia" )
116
+ # See:
117
+ # https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.hooks.html
118
+ # IPython.core.interactiveshell.init_completer
119
+ # IPython.core.completerlib (quick_completer etc.)
0 commit comments