Skip to content

Commit 352c26f

Browse files
authored
Support autocompletion of trigger symbols (#19)
By hacking into the REPL's keyword list
1 parent 7c3dff2 commit 352c26f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/BasicAutoloads.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@ function try_autoinstall(expr::Expr)
8282
end
8383

8484
is_repl_ready() = isdefined(Base, :active_repl_backend) && isdefined(Base.active_repl_backend, :ast_transforms)
85+
function _register_ast_transform_now(ast_transform)
86+
pushfirst!(Base.active_repl_backend.ast_transforms, ast_transform)
87+
# Hack the autolaods into autocompletion by hijacking REPL's list of keywords.
88+
# Workaround for https://github.com/JuliaLang/julia/issues/56101
89+
keywords = typeof(Base.active_repl_backend).name.module.REPLCompletions.sorted_keywords
90+
for trigger in keys(ast_transform.dict)
91+
str = string(trigger)
92+
insert!(keywords, searchsortedfirst(keywords, str), str)
93+
end
94+
end
8595
function _register_ast_transform(ast_transform)
8696
if is_repl_ready()
87-
pushfirst!(Base.active_repl_backend.ast_transforms, ast_transform)
97+
_register_ast_transform_now(ast_transform)
8898
else
8999
t = Task(_WaitRegisterASTTransform(ast_transform))
90100
schedule(t)
@@ -102,7 +112,7 @@ function (wrat::_WaitRegisterASTTransform)()
102112
sleep(.02*iter)
103113
end
104114
if is_repl_ready()
105-
pushfirst!(Base.active_repl_backend.ast_transforms, wrat.ast_transform)
115+
_register_ast_transform_now(wrat.ast_transform)
106116
else
107117
@warn "Timed out waiting for `Base.active_repl_backend.ast_transforms` to become available. Autoloads will not work."
108118
@info "If you have a slow startup file, consider moving `register_autoloads` to the end of it."

0 commit comments

Comments
 (0)