Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REPL] Autocompletion of ModuleName.@macro_name is broken #55518

Open
giordano opened this issue Aug 17, 2024 · 8 comments · May be fixed by #57767 or #56322
Open

[REPL] Autocompletion of ModuleName.@macro_name is broken #55518

giordano opened this issue Aug 17, 2024 · 8 comments · May be fixed by #57767 or #56322
Labels
bug Indicates an unexpected problem or unintended behavior completions Tab and autocompletion in the repl regression Regression in behavior compared to a previous version REPL Julia's REPL (Read Eval Print Loop)
Milestone

Comments

@giordano
Copy link
Contributor

giordano commented Aug 17, 2024

On 5230d27

julia> Base.@time nothi<TAB>

autocompletes nothi to nothing_sentinel:

julia> Base.@time nothing_sentinel
ERROR: UndefVarError: `nothing_sentinel` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] macro expansion
   @ ./timing.jl:579 [inlined]
 [2] top-level scope
   @ ./REPL[17]:1

If I understand it correctly, ModuleName.@macro symbol<TAB> autocompletes symbol inside ModuleName, not Main:

julia> module Issue55518
       macro name(expr) :($(esc(expr))) end
       const not_really_what_I_wanted = something
       end
Main.Issue55518

julia> using .Issue55518

julia> Issue55518.@name not<TAB>

This works correctly in Julia v1.10 and v1.11.0-rc1

@giordano giordano added bug Indicates an unexpected problem or unintended behavior REPL Julia's REPL (Read Eval Print Loop) regression Regression in behavior compared to a previous version labels Aug 17, 2024
@giordano giordano added this to the 1.12 milestone Aug 17, 2024
@giordano
Copy link
Contributor Author

I just ran again into this by trying to autocomplete in the REPL a Threads.@threads for loop.

@giordano
Copy link
Contributor Author

giordano commented Sep 24, 2024

We have an upgrade: also autocompletion of keyword arguments is now broken:

julia> module Issue55518
       macro name(expr) :($(esc(expr))) end
       const not_really_what_I_wanted = something
       f(; x) = x
       end
Main.Issue55518

julia> using .Issue55518

julia> Issue55518.f(; x=<TAB>
@name
eval
f
include
not_really_what_I_wanted

Trying to autocomplete the value of the keyword arguments complete only symbols within the module, also those that aren't exported and so you shouldn't even be able to reference them unless you imported them explicitly, which I didn't here.

@IanButterworth IanButterworth added the completions Tab and autocompletion in the repl label Sep 24, 2024
@giordano
Copy link
Contributor Author

giordano commented Oct 6, 2024

More on this:

julia> module Issue55518
           macro name(expr) :($(esc(expr))) end
           const not_really_what_I_wanted = something
           f(; x) = x
       end
Main.Issue55518

julia> using .Issue55518

julia> Issue55518.f; nothi<TAB>

doesn't complete the symbol after the semicolon, same for macros:

julia> Issue55518.f; @ti<TAB>

Basically after you type the module name you're damned to complete things within the module in the entire line, including after a semicolon to separate expressions.

@IanButterworth
Copy link
Member

@aviatesk any idea on this one? I think Mose's last summary above is key, I just can't figure out where the restriction to the module is happening.

@aviatesk
Copy link
Member

It looks like the prefix given to complete_symbol! is being something like :Issue55518 in those cases

complete_symbol!(suggestions, prefix, name, context_module; complete_modules_only, shift)

, which causes the method to use the prefix as the module context:
res = repl_eval_ex(prefix, context_module)
res === nothing && return Completion[]
if res isa Const
val = res.val
if isa(val, Module)
mod = val
if !shift
# when module is explicitly accessed, show internal bindings that are
# defined by the module, unless shift key is pressed
complete_internal_only = true
end
else
t = typeof(val)
end
else
t = CC.widenconst(res)
end

So I think we need to fix the prefix calculation that happens within complete_identifiers!.

@IanButterworth
Copy link
Member

I assume this is related to #54858 ? I see that's not on 1.11 and Base.@time nothi<TAB> works on 1.11

@giordano
Copy link
Contributor Author

giordano commented Dec 1, 2024

Other related breakage:

x = sin.([1]); y = ex<TAB>

completes to export, instead of exp. The dot again confuses everything. @aviatesk can you please take a look at this? TAB completetion in presence of dots horribly broken, making the REPL experience very frustrating.

@IanButterworth
Copy link
Member

We may want to revert the PR that introduced module specific completion. I think the experience may be worse than before that.

xal-0 added a commit to xal-0/julia that referenced this issue Mar 13, 2025
This commit replaces the heuristic parsing done by REPLCompletions.completions
with a new approach that parses the entire input buffer once with JuliaSyntax.
In addition to fixing bugs, the more precise parsing should allow for new
features in the future.

Some features now work in more situations "for free", like dictionary key
completion (the expression evaluated to find the keys is now more precise) and
method suggestions (arguments beyond the cursor can be used to narrow the list).

The tests have been updated to reflect slightly differing behaviour for string
and Cmd-string completion: the new code returns a character range encompassing
the entire string when completing paths (not observable by the user), and the
behaviour of '~'-expansion has be tweaked to be consistent across all places
where paths can be completed.  Some escaping issues have also been fixed.

Fixes: JuliaLang#55420, JuliaLang#55518, JuliaLang#55520, JuliaLang#55842, JuliaLang#56389, JuliaLang#57611
@xal-0 xal-0 linked a pull request Mar 13, 2025 that will close this issue
xal-0 added a commit to xal-0/julia that referenced this issue Mar 13, 2025
This commit replaces the heuristic parsing done by REPLCompletions.completions
with a new approach that parses the entire input buffer once with JuliaSyntax.
In addition to fixing bugs, the more precise parsing should allow for new
features in the future.

Some features now work in more situations "for free", like dictionary key
completion (the expression evaluated to find the keys is now more precise) and
method suggestions (arguments beyond the cursor can be used to narrow the list).

The tests have been updated to reflect slightly differing behaviour for string
and Cmd-string completion: the new code returns a character range encompassing
the entire string when completing paths (not observable by the user), and the
behaviour of '~'-expansion has be tweaked to be consistent across all places
where paths can be completed.  Some escaping issues have also been fixed.

Fixes: JuliaLang#55420, JuliaLang#55518, JuliaLang#55520, JuliaLang#55842, JuliaLang#56389, JuliaLang#57611
xal-0 added a commit to xal-0/julia that referenced this issue Mar 13, 2025
This commit replaces the heuristic parsing done by REPLCompletions.completions
with a new approach that parses the entire input buffer once with JuliaSyntax.
In addition to fixing bugs, the more precise parsing should allow for new
features in the future.

Some features now work in more situations "for free", like dictionary key
completion (the expression evaluated to find the keys is now more precise) and
method suggestions (arguments beyond the cursor can be used to narrow the list).

The tests have been updated to reflect slightly differing behaviour for string
and Cmd-string completion: the new code returns a character range encompassing
the entire string when completing paths (not observable by the user), and the
behaviour of '~'-expansion has be tweaked to be consistent across all places
where paths can be completed.  Some escaping issues have also been fixed.

Fixes: JuliaLang#55420, JuliaLang#55518, JuliaLang#55520, JuliaLang#55842, JuliaLang#56389, JuliaLang#57611
@giordano giordano linked a pull request Mar 14, 2025 that will close this issue
xal-0 added a commit to xal-0/julia that referenced this issue Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior completions Tab and autocompletion in the repl regression Regression in behavior compared to a previous version REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
3 participants