Skip to content

Commit a98e880

Browse files
aviateskKristofferC
authored andcommitted
enable completions for identifiers following ! operator (#34182)
1 parent 8a2059a commit a98e880

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ function completions(string, pos, context_module=Main)::Completions
612612
inc_tag==:string && return String[], 0:-1, false
613613
if inc_tag === :other && should_method_complete(partial)
614614
frange, method_name_end = find_start_brace(partial)
615-
ex = Meta.parse(partial[frange] * ")", raise=false, depwarn=false)
615+
# strip preceding ! operator
616+
s = replace(partial[frange], r"\!+([^=\(]+)" => s"\1")
617+
ex = Meta.parse(s * ")", raise=false, depwarn=false)
616618

617619
if isa(ex, Expr)
618620
if ex.head==:call
@@ -627,6 +629,10 @@ function completions(string, pos, context_module=Main)::Completions
627629

628630
dotpos = something(findprev(isequal('.'), string, pos), 0)
629631
startpos = nextind(string, something(findprev(in(non_identifier_chars), string, pos), 0))
632+
# strip preceding ! operator
633+
if (m = match(r"^\!+", string[startpos:pos])) !== nothing
634+
startpos += length(m.match)
635+
end
630636

631637
ffunc = (mod,x)->true
632638
suggestions = Completion[]

stdlib/REPL/test/replcompletions.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ let s = "Main.CompletionFoo.f"
138138
@test !("foobar" in c)
139139
end
140140

141+
# test method completions when `!` operator precedes
142+
let
143+
s = "!is"
144+
c, r = test_complete(s)
145+
@test "isa" in c
146+
@test s[r] == "is"
147+
@test !("!" in c)
148+
149+
s = "!!is"
150+
c, r = test_complete(s)
151+
@test "isa" in c
152+
@test s[r] == "is"
153+
@test !("!" in c)
154+
end
155+
141156
# issue #6424
142157
let s = "Main.CompletionFoo.@f"
143158
c, r = test_complete(s)
@@ -302,6 +317,27 @@ let s = "max("
302317
@test s[r] == "max"
303318
end
304319

320+
# test method completions when `!` operator precedes
321+
let
322+
s = "!("
323+
c, r, res = test_complete(s)
324+
@test !res
325+
@test all(m -> string(m) in c, methods(!))
326+
@test s[r] == s[1:end-1]
327+
328+
s = "!isnothing("
329+
c, r, res = test_complete(s)
330+
@test !res
331+
@test all(m -> string(m) in c, methods(isnothing))
332+
@test s[r] == s[1:end-1]
333+
334+
s = "!!isnothing("
335+
c, r, res = test_complete(s)
336+
@test !res
337+
@test all(m -> string(m) in c, methods(isnothing))
338+
@test s[r] == s[1:end-1]
339+
end
340+
305341
# Test completion of methods with input concrete args and args where typeinference determine their type
306342
let s = "CompletionFoo.test(1,1, "
307343
c, r, res = test_complete(s)

0 commit comments

Comments
 (0)