Skip to content

Commit

Permalink
Support autocompletion of trigger symbols (#19)
Browse files Browse the repository at this point in the history
By hacking into the REPL's keyword list
  • Loading branch information
LilithHafner authored Dec 4, 2024
1 parent 7c3dff2 commit 352c26f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/BasicAutoloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,19 @@ function try_autoinstall(expr::Expr)
end

is_repl_ready() = isdefined(Base, :active_repl_backend) && isdefined(Base.active_repl_backend, :ast_transforms)
function _register_ast_transform_now(ast_transform)
pushfirst!(Base.active_repl_backend.ast_transforms, ast_transform)
# Hack the autolaods into autocompletion by hijacking REPL's list of keywords.
# Workaround for https://github.com/JuliaLang/julia/issues/56101
keywords = typeof(Base.active_repl_backend).name.module.REPLCompletions.sorted_keywords
for trigger in keys(ast_transform.dict)
str = string(trigger)
insert!(keywords, searchsortedfirst(keywords, str), str)
end
end
function _register_ast_transform(ast_transform)
if is_repl_ready()
pushfirst!(Base.active_repl_backend.ast_transforms, ast_transform)
_register_ast_transform_now(ast_transform)
else
t = Task(_WaitRegisterASTTransform(ast_transform))
schedule(t)
Expand All @@ -102,7 +112,7 @@ function (wrat::_WaitRegisterASTTransform)()
sleep(.02*iter)
end
if is_repl_ready()
pushfirst!(Base.active_repl_backend.ast_transforms, wrat.ast_transform)
_register_ast_transform_now(wrat.ast_transform)
else
@warn "Timed out waiting for `Base.active_repl_backend.ast_transforms` to become available. Autoloads will not work."
@info "If you have a slow startup file, consider moving `register_autoloads` to the end of it."
Expand Down

2 comments on commit 352c26f

@LilithHafner
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/120638

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.4 -m "<description of version>" 352c26f73f7c35ef3f880ae1303ed08cabdf30bb
git push origin v1.0.4

Please sign in to comment.