Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Debugger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
26 changes: 20 additions & 6 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

@aviatesk aviatesk Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to remove the latter filter conditions here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have that in JuliaInterpreter as well but I am not sure I see the reason for it. I think it can be removed here anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, maybe @timholy knows that ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #self is probably sufficient. It's not always there (I can't remember where I recently encountered such a situation), but it should be sufficient. Assuming I started that trend I was probably just being paranoid.

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
11 changes: 5 additions & 6 deletions test/ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,20 @@ 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
frame = JuliaInterpreter.enter_call_expr(:($(F.f)(1)))
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