Skip to content

Commit

Permalink
Tweaks to repl tab complete hints (#51321)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Sep 14, 2023
1 parent d51ad06 commit d9a9be8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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 @@ -1701,6 +1701,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

0 comments on commit d9a9be8

Please sign in to comment.