Skip to content

Commit 824c99b

Browse files
complete imports when there are multiple macros before: Fixes JuliaLang#55429
1 parent 08d11d0 commit 824c99b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

stdlib/REPL/src/REPLCompletions.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,11 @@ const superscript_regex = Regex("^\\\\\\^[" * join(isdigit(k) || isletter(k) ? "
902902

903903
# Aux function to detect whether we're right after a using or import keyword
904904
function get_import_mode(s::String)
905-
# allow all of these to start with leading whitespace and macros like @eval and @eval(
906-
# ^\s*(?:@\w+\s*(?:\(\s*)?)?
905+
# allow all of these to start with leading whitespace and potentially multiple macros like @eval and @eval(
906+
prefix = raw"^\s*(?:@\w+\s*(?:\(\s*)?\s*)+$"
907907

908908
# match simple cases like `using |` and `import |`
909-
mod_import_match_simple = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s*$", s)
909+
mod_import_match_simple = match(Regex(prefix * raw"\b(using|import)\s*$"), s)
910910
if mod_import_match_simple !== nothing
911911
if mod_import_match_simple[1] == "using"
912912
return :using_module
@@ -915,7 +915,7 @@ function get_import_mode(s::String)
915915
end
916916
end
917917
# match module import statements like `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`
918-
mod_import_match = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s+([\w\.]+(?:\s*,\s*[\w\.]+)*),?\s*$", s)
918+
mod_import_match = match(Regex(prefix * raw"\b(using|import)\s+([\w\.]+(?:\s*,\s*[\w\.]+)*),?\s*$"), s)
919919
if mod_import_match !== nothing
920920
if mod_import_match.captures[1] == "using"
921921
return :using_module
@@ -924,7 +924,7 @@ function get_import_mode(s::String)
924924
end
925925
end
926926
# now match explicit name import statements like `using Foo: |` and `import Foo: bar, baz|`
927-
name_import_match = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s+([\w\.]+)\s*:\s*([\w@!\s,]+)$", s)
927+
name_import_match = match(Regex(prefix * raw"\b(using|import)\s+([\w\.]+)\s*:\s*([\w@!\s,]+)$"), s)
928928
if name_import_match !== nothing
929929
if name_import_match[1] == "using"
930930
return :using_name

stdlib/REPL/test/replcompletions.jl

+10
Original file line numberDiff line numberDiff line change
@@ -2269,11 +2269,21 @@ let s = "@time using .Iss"
22692269
@test res
22702270
@test "Issue52922" in c
22712271
end
2272+
let s = "@time @time @time using .Iss"
2273+
c, r, res = test_complete_context(s)
2274+
@test res
2275+
@test "Issue52922" in c
2276+
end
22722277
let s = " @time using .Iss"
22732278
c, r, res = test_complete_context(s)
22742279
@test res
22752280
@test "Issue52922" in c
22762281
end
2282+
let s = " @time @time using .Iss"
2283+
c, r, res = test_complete_context(s)
2284+
@test res
2285+
@test "Issue52922" in c
2286+
end
22772287
let s = "@time(using .Iss"
22782288
c, r, res = test_complete_context(s)
22792289
@test res

0 commit comments

Comments
 (0)