Skip to content
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

Tweaks to repl tab complete hints #51321

Merged
merged 2 commits into from
Sep 14, 2023
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
3 changes: 2 additions & 1 deletion stdlib/REPL/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ julia> mapfold[TAB]
mapfoldl mapfoldr
```

When a single complete tab-complete result is available a hint of the completion will show in a lighter color.
When a single complete tab-complete result is available at the end of an input line and 2 or more characters
have been typed, a hint of the completion will show in a lighter color.
This can be disabled via `Base.active_repl.options.hint_tab_completes = false`.

!!! compat "Julia 1.11"
Expand Down
6 changes: 6 additions & 0 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,13 @@ end
function check_for_hint(s::MIState)
st = state(s)
options(st).hint_tab_completes || return false
if !eof(buffer(st)) # only generate hints if at the end of the line
# TODO: maybe show hints for insertions at other positions
# Requires making space for them earlier in refresh_multi_line
return false
end
completions, partial, should_complete = complete_line(st.p.complete, st, s.active_module)::Tuple{Vector{String},String,Bool}
length(partial) < 2 && return false # Don't complete for single chars, given e.g. `x` completes to `xor`
if should_complete
if length(completions) == 1
hint = only(completions)[sizeof(partial)+1:end]
Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,13 @@ fake_repl() do stdin_write, stdout_read, repl
write(stdin_write, "\t")
s4 = readuntil(stdout_read, "readavailable") # full completion is reprinted

write(stdin_write, "\x15")
write(stdin_write, "x") # single chars shouldn't hint e.g. `x` shouldn't hint at `xor`
while LineEdit.state(repl.mistate).hint !== nothing
sleep(0.1)
end
@test LineEdit.state(repl.mistate).hint === nothing

write(stdin_write, "\x15\x04")
Base.wait(repltask)
end
Expand Down