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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ end

function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool = false, imported::Bool = false)
ssyms = names(mod, all = all, imported = imported)
all || filter!(Base.Fix1(Base.isexported, mod), ssyms)
Comment on lines 138 to +139
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)

filter!(ffunc, ssyms)
macros = filter(x -> startswith(String(x), "@" * name), ssyms)
syms = String[sprint((io,s)->Base.show_sym(io, s; allow_macroname=true), s) for s in ssyms if completes_global(String(s), name)]
Expand Down
14 changes: 14 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1896,3 +1896,17 @@ let s = "Issue49892(fal"
@test n in c
end
end

@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(

@test "ispublic" c

c, r, res = test_complete("Base.ispub")
@test res
@test "ispublic" c

@test Base.ispublic(Base, :ispublic)
# If this last test starts failing, that's okay, just pick a new example symbol:
@test !Base.isexported(Base, :ispublic)
end