@@ -190,7 +190,7 @@ function parse_input(str)
190
190
end
191
191
192
192
function match_magic_syntax (str)
193
- m = match (r" ^(%module|\? ) *(.*)" , str)
193
+ m = match (r" ^(%module|\? |%include ) *(.*)" , str)
194
194
if ! isnothing (m)
195
195
return (m[1 ], m[2 ])
196
196
else
@@ -202,7 +202,11 @@ function valid_input_checker(prompt_state)
202
202
cmdstr = String (take! (copy (REPL. LineEdit. buffer (prompt_state))))
203
203
magic = match_magic_syntax (cmdstr)
204
204
if ! isnothing (magic)
205
- cmdstr = magic[2 ]
205
+ if magic[1 ] in (" %module" , " ?" )
206
+ cmdstr = magic[2 ]
207
+ elseif magic[1 ] == " %include"
208
+ return true
209
+ end
206
210
end
207
211
ex = parse_input (cmdstr)
208
212
return ! Meta. isexpr (ex, :incomplete )
@@ -212,14 +216,36 @@ struct RemoteCompletionProvider <: REPL.LineEdit.CompletionProvider
212
216
connection
213
217
end
214
218
219
+ function path_str (path_completion)
220
+ path = REPL. REPLCompletions. completion_text (path_completion)
221
+ if Sys. iswindows ()
222
+ # On windows, REPLCompletions.complete_path() adds extra escapes for
223
+ # use within a normal string in the Juila REPL but we don't need those.
224
+ path = replace (path, " \\\\ " => ' \\ ' )
225
+ end
226
+ return path
227
+ end
228
+
215
229
function REPL. complete_line (provider:: RemoteCompletionProvider ,
216
230
state:: REPL.LineEdit.PromptState ): :
217
231
Tuple{Vector{String},String,Bool}
218
232
# See REPL.jl complete_line(c::REPLCompletionProvider, s::PromptState)
219
233
partial = REPL. beforecursor (state. input_buffer)
220
234
full = REPL. LineEdit. input_string (state)
221
- if ! isempty (full) && startswith (" %modul" , full)
222
- return ([" %module" ], full, true )
235
+ if startswith (full, " %m" )
236
+ if startswith (" %module" , full)
237
+ return ([" %module " ], full, true )
238
+ end
239
+ elseif startswith (full, " %i" )
240
+ if startswith (" %include" , full)
241
+ return ([" %include " ], full, true )
242
+ elseif startswith (full, " %include " )
243
+ _, path_prefix = match_magic_syntax (full)
244
+ (path_completions, range, should_complete) =
245
+ REPL. REPLCompletions. complete_path (path_prefix, length (path_prefix))
246
+ completions = [path_str (c) for c in path_completions]
247
+ return (completions, path_prefix[range], should_complete)
248
+ end
223
249
end
224
250
result = ensure_connected! (provider. connection) do
225
251
send_and_receive (provider. connection, (:repl_completion , (partial, full)))
@@ -275,6 +301,19 @@ function run_remote_repl_command(conn, out_stream, cmdstr)
275
301
elseif magic[1 ] == " %module"
276
302
mod_ex = Meta. parse (magic[2 ])
277
303
cmd = (:in_module , mod_ex)
304
+ elseif magic[1 ] == " %include"
305
+ path = abspath (magic[2 ])
306
+ text = read (path, String)
307
+ # Some rough heuristics to construct a file URI. This gives us
308
+ # a place to put the host name.
309
+ if ! startswith (path, ' /' )
310
+ path = ' /' * path
311
+ end
312
+ if Sys. iswindows ()
313
+ path = replace (path, ' \\ ' => ' /' )
314
+ end
315
+ path_uri = " file://$(gethostname ())$path "
316
+ cmd = (:eval , :(Base. include_string (@__MODULE__ , $ text, $ path_uri)))
278
317
end
279
318
end
280
319
messageid, value = send_and_receive (conn, cmd)
0 commit comments