diff --git a/src/Debugger.jl b/src/Debugger.jl index 259bc51..0165b71 100644 --- a/src/Debugger.jl +++ b/src/Debugger.jl @@ -11,10 +11,10 @@ using REPL.LineEdit using REPL.REPLCompletions using CodeTracking -using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root, BreakpointState, +using JuliaInterpreter: JuliaInterpreter, Frame, @lookup, FrameCode, BreakpointRef, debug_command, leaf, root, BreakpointState, finish_and_return!, Compiled -using JuliaInterpreter: pc_expr, moduleof, linenumber, extract_args, +using JuliaInterpreter: pc_expr, moduleof, linenumber, extract_args, locals, root, caller, whereis, get_return, nstatements, getargs const SEARCH_PATH = [] diff --git a/src/repl.jl b/src/repl.jl index cdcd00f..77cb74f 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -220,14 +220,28 @@ end function LineEdit.complete_line(c::DebugCompletionProvider, s) partial = REPL.beforecursor(s.input_buffer) full = LineEdit.input_string(s) - ret, range, should_complete = completions(c, full, lastindex(partial)) - return unique!(map(REPLCompletions.completion_text, ret)), partial[range], should_complete + + ret, range, should_complete = completions(c, full, partial) + return ret, partial[range], should_complete end function completions(c::DebugCompletionProvider, full, partial) - mod = moduleof(c.state.frame) - ret, range, should_complete = REPLCompletions.completions(full, partial, mod) + frame = c.state.frame + + # repl backend completions + comps, range, should_complete = REPLCompletions.completions(full, lastindex(partial), moduleof(frame)) + ret = map(REPLCompletions.completion_text, comps) |> unique! + + # local completions + vars = filter!(locals(frame)) do v + # ref: https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/master/src/utils.jl#L365-L370 + if v.name == Symbol("#self") && (v.value isa Type || sizeof(v.value) == 0) + return false + else + return startswith(string(v.name), partial) + end + end |> vars -> map(v -> string(v.name), vars) + pushfirst!(ret, vars...) - # TODO Add local variable completions - return ret, range, should_complete + ret, range, should_complete end diff --git a/test/ui.jl b/test/ui.jl index 5356f1e..b7b023d 100644 --- a/test/ui.jl +++ b/test/ui.jl @@ -169,14 +169,11 @@ end end # Completions -function test_complete(c, s) - c, r, s = Debugger.completions(c, s, lastindex(s)) - return unique!(map(REPL.REPLCompletions.completion_text, c)), r, s -end +test_complete(c, s) = Debugger.completions(c, s, s) module F local_var = 1 - f(x) = x + f(f_args) = f_args end @testset "REPL completions" begin @@ -184,6 +181,8 @@ end state = dummy_state(frame) prov = Debugger.DebugCompletionProvider(state) - c, r = test_complete(prov, "local") + c, _ = test_complete(prov, "local") @test "local_var" in c + c, _ = test_complete(prov, "f_") + @test "f_args" in c end