From 550f5742350ddce047117b8f963a5be78c3bd4cc Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 14 Sep 2023 21:56:11 -0400 Subject: [PATCH 1/2] complete false & true more generally as vals --- stdlib/REPL/src/REPLCompletions.jl | 37 +++++++++++++++++++---------- stdlib/REPL/test/replcompletions.jl | 9 +++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index f8aca313b8c05..e775a31a18c6b 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -19,6 +19,10 @@ struct KeywordCompletion <: Completion keyword::String end +struct KeyvalCompletion <: Completion + keyval::String +end + struct PathCompletion <: Completion path::String end @@ -99,6 +103,7 @@ end _completion_text(c::TextCompletion) = c.text _completion_text(c::KeywordCompletion) = c.keyword +_completion_text(c::KeyvalCompletion) = c.keyval _completion_text(c::PathCompletion) = c.path _completion_text(c::ModuleCompletion) = c.mod _completion_text(c::PackageCompletion) = c.package @@ -220,24 +225,30 @@ function add_field_completions!(suggestions::Vector{Completion}, name::String, @ end end +function complete_from_list(T::Type, list::Vector{String}, s::Union{String,SubString{String}}) + r = searchsorted(list, s) + i = first(r) + n = length(list) + while i <= n && startswith(list[i],s) + r = first(r):i + i += 1 + end + Completion[T(kw) for kw in list[r]] +end + const sorted_keywords = [ "abstract type", "baremodule", "begin", "break", "catch", "ccall", - "const", "continue", "do", "else", "elseif", "end", "export", "false", + "const", "continue", "do", "else", "elseif", "end", "export", "finally", "for", "function", "global", "if", "import", "let", "local", "macro", "module", "mutable struct", "primitive type", "quote", "return", "struct", - "true", "try", "using", "while"] + "try", "using", "while"] -function complete_keyword(s::Union{String,SubString{String}}) - r = searchsorted(sorted_keywords, s) - i = first(r) - n = length(sorted_keywords) - while i <= n && startswith(sorted_keywords[i],s) - r = first(r):i - i += 1 - end - Completion[KeywordCompletion(kw) for kw in sorted_keywords[r]] -end +complete_keyword(s::Union{String,SubString{String}}) = complete_from_list(KeywordCompletion, sorted_keywords, s) + +const sorted_keyvals = ["false", "true"] + +complete_keyval(s::Union{String,SubString{String}}) = complete_from_list(KeyvalCompletion, sorted_keyvals, s) function complete_path(path::AbstractString, pos::Int; use_envpath=false, shell_escape=false, @@ -926,6 +937,7 @@ function complete_keyword_argument(partial, last_idx, context_module) suggestions = Completion[KeywordArgumentCompletion(kwarg) for kwarg in kwargs] append!(suggestions, complete_symbol(nothing, last_word, Returns(true), context_module)) + append!(suggestions, complete_keyval(last_word)) return sort!(suggestions, by=completion_text), wordrange end @@ -949,6 +961,7 @@ end function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ffunc::Function), context_module::Module, string::String, name::String, pos::Int, dotpos::Int, startpos::Int, comp_keywords=false) ex = nothing comp_keywords && append!(suggestions, complete_keyword(name)) + append!(suggestions, complete_keyval(name)) if dotpos > 1 && string[dotpos] == '.' s = string[1:dotpos-1] # First see if the whole string up to `pos` is a valid expression. If so, use it. diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index 4f03f5ab79894..ab44ba163058f 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -1887,3 +1887,12 @@ let s = "union_some_ref(1, 1.0)." @test res @test "value" in c && "x" in c end + +Issue49892(x) = x +let s = "Issue49892(fal" + c, r, res = test_complete_context(s, @__MODULE__) + @test res + for n in ("false", "falses") + @test n in c + end +end From 2cd3380373e489dbdad93867a94f1d383233addb Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 14 Sep 2023 22:56:51 -0400 Subject: [PATCH 2/2] tryfix --- stdlib/REPL/src/REPLCompletions.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index e775a31a18c6b..8ceed06d1c5df 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -960,8 +960,10 @@ end function complete_identifiers!(suggestions::Vector{Completion}, @nospecialize(ffunc::Function), context_module::Module, string::String, name::String, pos::Int, dotpos::Int, startpos::Int, comp_keywords=false) ex = nothing - comp_keywords && append!(suggestions, complete_keyword(name)) - append!(suggestions, complete_keyval(name)) + if comp_keywords + append!(suggestions, complete_keyword(name)) + append!(suggestions, complete_keyval(name)) + end if dotpos > 1 && string[dotpos] == '.' s = string[1:dotpos-1] # First see if the whole string up to `pos` is a valid expression. If so, use it.