Skip to content

Commit

Permalink
REPL: enable import completion when in a macro (#55366)
Browse files Browse the repository at this point in the history
Fixes #55361

I think this regressed in #54719
given tests didn't include leading spaces/macros
  • Loading branch information
IanButterworth authored Aug 4, 2024
1 parent 2a56b78 commit 22e5362
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,11 @@ const superscript_regex = Regex("^\\\\\\^[" * join(isdigit(k) || isletter(k) ? "

# Aux function to detect whether we're right after a using or import keyword
function get_import_mode(s::String)
# allow all of these to start with leading whitespace and macros like @eval and @eval(
# ^\s*(?:@\w+\s*(?:\(\s*)?)?

# match simple cases like `using |` and `import |`
mod_import_match_simple = match(r"^\b(using|import)\s*$", s)
mod_import_match_simple = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s*$", s)
if mod_import_match_simple !== nothing
if mod_import_match_simple[1] == "using"
return :using_module
Expand All @@ -910,7 +913,7 @@ function get_import_mode(s::String)
end
end
# match module import statements like `using Foo|`, `import Foo, Bar|` and `using Foo.Bar, Baz, |`
mod_import_match = match(r"^\b(using|import)\s+([\w\.]+(?:\s*,\s*[\w\.]+)*),?\s*$", s)
mod_import_match = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s+([\w\.]+(?:\s*,\s*[\w\.]+)*),?\s*$", s)
if mod_import_match !== nothing
if mod_import_match.captures[1] == "using"
return :using_module
Expand All @@ -919,7 +922,7 @@ function get_import_mode(s::String)
end
end
# now match explicit name import statements like `using Foo: |` and `import Foo: bar, baz|`
name_import_match = match(r"^\b(using|import)\s+([\w\.]+)\s*:\s*([\w@!\s,]+)$", s)
name_import_match = match(r"^\s*(?:@\w+\s*(?:\(\s*)?)?\b(using|import)\s+([\w\.]+)\s*:\s*([\w@!\s,]+)$", s)
if name_import_match !== nothing
if name_import_match[1] == "using"
return :using_name
Expand Down
20 changes: 20 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2238,6 +2238,26 @@ let s = "using .Iss"
@test res
@test "Issue52922" in c
end
let s = " using .Iss"
c, r, res = test_complete_context(s)
@test res
@test "Issue52922" in c
end
let s = "@time using .Iss"
c, r, res = test_complete_context(s)
@test res
@test "Issue52922" in c
end
let s = " @time using .Iss"
c, r, res = test_complete_context(s)
@test res
@test "Issue52922" in c
end
let s = "@time(using .Iss"
c, r, res = test_complete_context(s)
@test res
@test "Issue52922" in c
end
let s = "using .Issue52922.Inn"
c, r, res = test_complete_context(s)
@test res
Expand Down

0 comments on commit 22e5362

Please sign in to comment.