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

Don't give public but unexported symbols as repl completions in an unqualified context #51345

Merged
merged 1 commit into from
Sep 17, 2023

Conversation

LilithHafner
Copy link
Member

Fixes #51331
Bug introduced by #50105

@LilithHafner LilithHafner added REPL Julia's REPL (Read Eval Print Loop) bugfix This change fixes an existing bug labels Sep 16, 2023

@testset "public but non-exported symbols only complete qualified (#51331)" begin
c, r, res = test_complete("ispub")
@test res
Copy link
Member

Choose a reason for hiding this comment

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

What is res actually testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's something about the type of completion, perhaps weather or not it is ever sensible to display the completion inline. For example, IICU, we never display argument hints inline.

julia> completions("summ", 4)
(REPL.REPLCompletions.Completion[REPL.REPLCompletions.ModuleCompletion(Base, "summary"), REPL.REPLCompletions.ModuleCompletion(Base, "summarysize")], 1:4, true)

julia> completions("summary(", 8)
(REPL.REPLCompletions.Completion[REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), Base.JuliaSyntax.SyntaxHead}, summary(head::Base.JuliaSyntax.SyntaxHead) @ Base.JuliaSyntax ~/.julia/dev/julia/base/JuliaSyntax/src/parse_stream.jl:98), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), Base.JuliaSyntax.GreenNode}, summary(node::Base.JuliaSyntax.GreenNode) @ Base.JuliaSyntax ~/.julia/dev/julia/base/JuliaSyntax/src/green_tree.jl:39), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, Function}, summary(io::IO, f::Function) @ Base show.jl:3111), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, AbstractDict}, summary(io::IO, t::AbstractDict) @ Base abstractdict.jl:33), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, T} where T<:Union{Base.KeySet, Base.ValueIterator}, summary(io::IO, iter::T) where T<:Union{KeySet, ValueIterator} @ Base abstractdict.jl:51), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, AbstractString}, summary(io::IO, s::AbstractString) @ Base strings/basic.jl:234), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, AbstractSet}, summary(io::IO, t::AbstractSet) @ Base show.jl:214), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, AbstractArray}, summary(io::IO, a::AbstractArray) @ Base show.jl:3099), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), IO, Any}, summary(io::IO, x) @ Base show.jl:3081), REPL.REPLCompletions.MethodCompletion(Tuple{typeof(summary), Any}, summary(x) @ Base show.jl:3082)], 1:7, false)

julia> summary(
summary(head::Base.JuliaSyntax.SyntaxHead) @ Base.JuliaSyntax ~/.julia/dev/julia/base/JuliaSyntax/src/parse_stream.jl:98
summary(node::Base.JuliaSyntax.GreenNode) @ Base.JuliaSyntax ~/.julia/dev/julia/base/JuliaSyntax/src/green_tree.jl:39
summary(io::IO, f::Function) @ Base show.jl:3111
summary(io::IO, t::AbstractDict) @ Base abstractdict.jl:33
summary(io::IO, iter::T) where T<:Union{KeySet, ValueIterator} @ Base abstractdict.jl:51
summary(io::IO, s::AbstractString) @ Base strings/basic.jl:234
summary(io::IO, t::AbstractSet) @ Base show.jl:214
summary(io::IO, a::AbstractArray) @ Base show.jl:3099
summary(io::IO, x) @ Base show.jl:3081
summary(x) @ Base show.jl:3082
julia> summary(

@LilithHafner LilithHafner added the merge me PR is reviewed. Merge when all tests are passing label Sep 16, 2023
Comment on lines 138 to +139
ssyms = names(mod, all = all, imported = imported)
all || filter!(Base.Fix1(Base.isexported, mod), ssyms)
Copy link
Member

Choose a reason for hiding this comment

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

What about making this an option on names. Seems useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

We considered that for a bit here, but I ended up thinking that the predicates we use to filter the names are awfully complicated and hard to understand and accurately document as is:

julia/src/module.c

Lines 955 to 959 in ebe1a37

int hidden = jl_symbol_name(asname)[0]=='#';
if ((b->publicp ||
(imported && b->imported) ||
(jl_atomic_load_relaxed(&b->owner) == b && !b->imported && (all || m == jl_main_module))) &&
(all || (!b->deprecated && !hidden))) {

and that it would be better to give users access to a full list of names and a set of predicates to filter with themselves. This arises from the belief that complex configuration is better expressed with code than keywords.

(I'm merging this bugfix now, but that does not close this discussion, feel free to open a feature request issue)

@LilithHafner LilithHafner merged commit 26ceebf into master Sep 17, 2023
4 checks passed
@LilithHafner LilithHafner deleted the lh/replcompletions-qualification branch September 17, 2023 12:25
@LilithHafner LilithHafner removed the merge me PR is reviewed. Merge when all tests are passing label Sep 17, 2023
NHDaly pushed a commit that referenced this pull request Sep 20, 2023
Pangoraw added a commit to Pangoraw/FuzzyCompletions.jl that referenced this pull request Oct 7, 2023
aviatesk pushed a commit to JunoLab/FuzzyCompletions.jl that referenced this pull request Oct 25, 2023
* Backport several changes from `REPL.REPLCompletions`

 - JuliaLang/julia#51502
 - JuliaLang/julia#51345

* make field_completion_eligible true for 1.6

Base._which was added in
JuliaLang/julia@7b19e09

* Update FuzzyCompletions.jl
aviatesk added a commit that referenced this pull request Dec 20, 2023
Fix #52551.

This PR ensures that a `SomeModule.?(...#TAB` completion can only
suggests method `foo` such that `SomeModule.foo` exists (by checking
`isdefined(SomeModule, :foo)`). This is equivalent, I believe, to the
initial implementation of #38791,
less the bug.

Now that we have #51345, we may want to relax the above condition
somewhat to include public names present in modules loaded into
`SomeModule`, so that, for instance, a direct completion of `?(` would
include `@assume_effects`. This could be good for method exploration
because even though typing `@assume_effects` with no qualification in
`Main` will error, the error now includes the helpful message
```
Hint: a global variable of this name also exists in Base.
```
But that can wait for a later PR anyway, this one is just the bugfix.

The bug mentioned at
#52551 (comment)
dates from the initial #38791 so this could be backported as far back as
v1.8.

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
KristofferC pushed a commit that referenced this pull request Dec 23, 2023
Fix #52551.

This PR ensures that a `SomeModule.?(...#TAB` completion can only
suggests method `foo` such that `SomeModule.foo` exists (by checking
`isdefined(SomeModule, :foo)`). This is equivalent, I believe, to the
initial implementation of #38791,
less the bug.

Now that we have #51345, we may want to relax the above condition
somewhat to include public names present in modules loaded into
`SomeModule`, so that, for instance, a direct completion of `?(` would
include `@assume_effects`. This could be good for method exploration
because even though typing `@assume_effects` with no qualification in
`Main` will error, the error now includes the helpful message
```
Hint: a global variable of this name also exists in Base.
```
But that can wait for a later PR anyway, this one is just the bugfix.

The bug mentioned at
#52551 (comment)
dates from the initial #38791 so this could be backported as far back as
v1.8.

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
(cherry picked from commit a987f56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tab-completion completes public but unexported symbols without qualification
3 participants