Skip to content

Commit 8cb3197

Browse files
complete false & true more generally as vals (#51326)
(cherry picked from commit e85f0a5)
1 parent 510550b commit 8cb3197

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

stdlib/REPL/src/REPLCompletions.jl

+28-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ struct KeywordCompletion <: Completion
1919
keyword::String
2020
end
2121

22+
struct KeyvalCompletion <: Completion
23+
keyval::String
24+
end
25+
2226
struct PathCompletion <: Completion
2327
path::String
2428
end
@@ -99,6 +103,7 @@ end
99103

100104
_completion_text(c::TextCompletion) = c.text
101105
_completion_text(c::KeywordCompletion) = c.keyword
106+
_completion_text(c::KeyvalCompletion) = c.keyval
102107
_completion_text(c::PathCompletion) = c.path
103108
_completion_text(c::ModuleCompletion) = c.mod
104109
_completion_text(c::PackageCompletion) = c.package
@@ -213,24 +218,30 @@ function complete_symbol(@nospecialize(ex), name::String, @nospecialize(ffunc),
213218
suggestions
214219
end
215220

221+
function complete_from_list(T::Type, list::Vector{String}, s::Union{String,SubString{String}})
222+
r = searchsorted(list, s)
223+
i = first(r)
224+
n = length(list)
225+
while i <= n && startswith(list[i],s)
226+
r = first(r):i
227+
i += 1
228+
end
229+
Completion[T(kw) for kw in list[r]]
230+
end
231+
216232
const sorted_keywords = [
217233
"abstract type", "baremodule", "begin", "break", "catch", "ccall",
218-
"const", "continue", "do", "else", "elseif", "end", "export", "false",
234+
"const", "continue", "do", "else", "elseif", "end", "export",
219235
"finally", "for", "function", "global", "if", "import",
220236
"let", "local", "macro", "module", "mutable struct",
221237
"primitive type", "quote", "return", "struct",
222-
"true", "try", "using", "while"]
238+
"try", "using", "while"]
223239

224-
function complete_keyword(s::Union{String,SubString{String}})
225-
r = searchsorted(sorted_keywords, s)
226-
i = first(r)
227-
n = length(sorted_keywords)
228-
while i <= n && startswith(sorted_keywords[i],s)
229-
r = first(r):i
230-
i += 1
231-
end
232-
Completion[KeywordCompletion(kw) for kw in sorted_keywords[r]]
233-
end
240+
complete_keyword(s::Union{String,SubString{String}}) = complete_from_list(KeywordCompletion, sorted_keywords, s)
241+
242+
const sorted_keyvals = ["false", "true"]
243+
244+
complete_keyval(s::Union{String,SubString{String}}) = complete_from_list(KeyvalCompletion, sorted_keyvals, s)
234245

235246
function complete_path(path::AbstractString, pos::Int;
236247
use_envpath=false, shell_escape=false,
@@ -919,6 +930,7 @@ function complete_keyword_argument(partial, last_idx, context_module)
919930

920931
suggestions = Completion[KeywordArgumentCompletion(kwarg) for kwarg in kwargs]
921932
append!(suggestions, complete_symbol(nothing, last_word, Returns(true), context_module))
933+
append!(suggestions, complete_keyval(last_word))
922934

923935
return sort!(suggestions, by=completion_text), wordrange
924936
end
@@ -941,7 +953,10 @@ end
941953

942954
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)
943955
ex = nothing
944-
comp_keywords && append!(suggestions, complete_keyword(name))
956+
if comp_keywords
957+
append!(suggestions, complete_keyword(name))
958+
append!(suggestions, complete_keyval(name))
959+
end
945960
if dotpos > 1 && string[dotpos] == '.'
946961
s = string[1:prevind(string, dotpos)]
947962
# First see if the whole string up to `pos` is a valid expression. If so, use it.

stdlib/REPL/test/replcompletions.jl

+9
Original file line numberDiff line numberDiff line change
@@ -1880,3 +1880,12 @@ let s = "`abc`.e"
18801880
# (completions for the fields of `Cmd`)
18811881
@test c == Any["env", "exec"]
18821882
end
1883+
1884+
Issue49892(x) = x
1885+
let s = "Issue49892(fal"
1886+
c, r, res = test_complete_context(s, @__MODULE__)
1887+
@test res
1888+
for n in ("false", "falses")
1889+
@test n in c
1890+
end
1891+
end

0 commit comments

Comments
 (0)