Skip to content

Commit 2638891

Browse files
IanButterworthNHDaly
authored andcommitted
Tweaks to repl tab complete hints (#51321)
1 parent 31280a2 commit 2638891

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

stdlib/REPL/docs/src/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ julia> mapfold[TAB]
334334
mapfoldl mapfoldr
335335
```
336336

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

340341
!!! compat "Julia 1.11"

stdlib/REPL/src/LineEdit.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,13 @@ end
376376
function check_for_hint(s::MIState)
377377
st = state(s)
378378
options(st).hint_tab_completes || return false
379+
if !eof(buffer(st)) # only generate hints if at the end of the line
380+
# TODO: maybe show hints for insertions at other positions
381+
# Requires making space for them earlier in refresh_multi_line
382+
return false
383+
end
379384
completions, partial, should_complete = complete_line(st.p.complete, st, s.active_module)::Tuple{Vector{String},String,Bool}
385+
length(partial) < 2 && return false # Don't complete for single chars, given e.g. `x` completes to `xor`
380386
if should_complete
381387
if length(completions) == 1
382388
hint = only(completions)[sizeof(partial)+1:end]

stdlib/REPL/test/repl.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,13 @@ fake_repl() do stdin_write, stdout_read, repl
17011701
write(stdin_write, "\t")
17021702
s4 = readuntil(stdout_read, "readavailable") # full completion is reprinted
17031703

1704+
write(stdin_write, "\x15")
1705+
write(stdin_write, "x") # single chars shouldn't hint e.g. `x` shouldn't hint at `xor`
1706+
while LineEdit.state(repl.mistate).hint !== nothing
1707+
sleep(0.1)
1708+
end
1709+
@test LineEdit.state(repl.mistate).hint === nothing
1710+
17041711
write(stdin_write, "\x15\x04")
17051712
Base.wait(repltask)
17061713
end

0 commit comments

Comments
 (0)