From 1d5d973112f772bd4c155f134e4fa0ad4385f6fd Mon Sep 17 00:00:00 2001 From: Casey Duckering Date: Mon, 20 Jul 2020 03:48:49 -0500 Subject: [PATCH] Add completion for cell macros --- src/execute_request.jl | 5 +++++ src/handlers.jl | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/execute_request.jl b/src/execute_request.jl index 344e736d..f06c62b3 100644 --- a/src/execute_request.jl +++ b/src/execute_request.jl @@ -28,6 +28,11 @@ function run_cell_code(code) if startswith(code, "@@") lines = split(code, '\n') for line in lines + line = strip(line) + if length(line) <= 0 + line_no += 1 + continue + end startswith(line, "@@") || break mac_call = Meta.parse(line[nextind("abc", 0, 2):end]) @assert Meta.isexpr(mac_call, :macrocall) diff --git a/src/handlers.jl b/src/handlers.jl index a0e25a56..a2e0f5a4 100644 --- a/src/handlers.jl +++ b/src/handlers.jl @@ -7,10 +7,22 @@ using .CommManager parseok(s) = !Meta.isexpr(Meta.parse(s, raise=false), :error) function find_parsestart(code, cursorpos) s = firstindex(code) + in_macro_header = true while s < cursorpos + s_next = nextind(code, s) + if in_macro_header && s_next <= cursorpos && code[s:s_next] == "@@" + # Skip first '@' to pretend it's a normal macro for completion + s, s_next = s_next, nextind(code, s_next) + else + in_macro_header = false + end parseok(code[s:cursorpos]) && return s - s = nextind(code, s) - while s < cursorpos && code[s] ∉ ('\n','\r') + # Go to next line + s = s_next + while s < cursorpos && code[s] ∉ "\n\r" + s = nextind(code, s) + end + while s < cursorpos && code[s] ∈ "\n\r \t" s = nextind(code, s) end end