Skip to content

Fix completion at the end of a complete line #4373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 13 additions & 1 deletion ext/REPLExt/REPLExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool = false)
partial = REPL.beforecursor(s.input_buffer)
full = LineEdit.input_string(s)
ret, range, should_complete = completions(full, lastindex(partial); hint)
return ret, partial[range], should_complete
# Convert to new completion interface format
named_completions = map(LineEdit.NamedCompletion, ret)
# Convert UnitRange to Region (Pair{Int,Int}) to match new completion interface
# range represents character positions in full string, convert to 0-based byte positions
if isempty(range)
region = 0 => 0
else
# Convert 1-based character positions to 0-based byte positions
start_pos = thisind(full, first(range)) - 1
end_pos = thisind(full, last(range))
region = start_pos => end_pos
end
return named_completions, region, should_complete
end

prev_project_file = nothing
Expand Down
24 changes: 24 additions & 0 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,28 @@ end
end
end

@testset "Pkg completion - edit_move_right fix (issue #58690)" begin
# Test that edit_move_right doesn't crash with Pkg completions
# This reproduces the issue where pressing right arrow after typing "add minimap2" would crash
temp_pkg_dir() do project_path
with_pkg_env(project_path) do
# Create a fake terminal and prompt state
term = REPL.Terminals.TTYTerminal("xterm", stdin, stdout, stderr)
prompt = REPL.LineEdit.Prompt("pkg> ")
prompt.complete = REPLExt.PkgCompletionProvider()

s = REPL.LineEdit.MIState(term, prompt, nothing, [prompt])
REPL.LineEdit.mode(s, prompt)
ps = REPL.LineEdit.state(s, prompt)

# Set up the input buffer with the problematic text
write(ps.input_buffer, "add minimap2")
seek(ps.input_buffer, sizeof("add minimap2"))

# This should not throw an error (it used to throw FieldError)
@test_nowarn REPL.LineEdit.edit_move_right(s)
end
end
end

end # module
Loading