From 052d4c766e47a566470b6865f8a074fa9a8d1448 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 13 Sep 2023 20:20:36 -0400 Subject: [PATCH 1/2] only generate hints at the end of the line --- stdlib/REPL/docs/src/index.md | 3 ++- stdlib/REPL/src/LineEdit.jl | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index 67b64c6ca5168..1e06c5ea1615f 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -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 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" diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index ae928cb8e5082..729141de393de 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -376,6 +376,11 @@ 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} if should_complete if length(completions) == 1 From 8743920f8797eac79ade775ea37966041ca7f30e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 14 Sep 2023 16:33:26 -0400 Subject: [PATCH 2/2] only hint for 2 chars or more --- stdlib/REPL/docs/src/index.md | 4 ++-- stdlib/REPL/src/LineEdit.jl | 1 + stdlib/REPL/test/repl.jl | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index 1e06c5ea1615f..d1064d9c063b4 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -334,8 +334,8 @@ julia> mapfold[TAB] mapfoldl mapfoldr ``` -When a single complete tab-complete result is available at the end of an input line 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" diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index 729141de393de..65cf81c3d6050 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -382,6 +382,7 @@ function check_for_hint(s::MIState) 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] diff --git a/stdlib/REPL/test/repl.jl b/stdlib/REPL/test/repl.jl index 6bf65279a6b82..cd22963ebf97c 100644 --- a/stdlib/REPL/test/repl.jl +++ b/stdlib/REPL/test/repl.jl @@ -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