-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
wip: REPLCompletions: allow completions for using
-ed names
#42092
Conversation
Open questions for reviewers:
Thanks! 😊 |
|
…dules ```julia julia> module TestMod42092 module M1 const m1_x = 1 export m1_x end module M2 const m2_x = 1 export m2_x end module A module B f(x) = 1 secret = 1 module Inner2 end end module C x = 1 y = 2 export y end using .B: f using .C using ..M1 import ..M2 end end # module TestMod42092 Main.TestMod42092 julia> LookingGlass.module_recursive_globals(TestMod42092.A, imported=true, usings=true) Dict{Tuple{Module, Symbol}, Int64} with 7 entries: (Main.TestMod42092.M2, :m2_x) => 1 (Main.TestMod42092.A, :y) => 2 (Main.TestMod42092.A.C, :y) => 2 (Main.TestMod42092.A.B, :secret) => 1 (Main.TestMod42092.A.C, :x) => 1 (Main.TestMod42092.A, :m1_x) => 1 (Main.TestMod42092.M1, :m1_x) => 1 ``` NOTE: the `usings=true` option is in PR against Julia 1.8. See: JuliaLang/julia#42092
yeah, I think the manual binding lookup is valid here in terms of the functionality of
I think we can add bindings that are explicitly julia> using Base: @aggressive_constantprop
julia> @aggressive_ # tab completion doesn't work w/ this PR Here is the corresponding test case I added in #42094: julia/stdlib/REPL/test/replcompletions.jl Lines 1194 to 1200 in 66b9235
I'm not sure what is the most consistent behavior, but at least I want to remove this special casing for every case ? Lines 815 to 817 in e0ac286
I don't have much opinion on naming in general, but /cc @pfitzseb The LS might also be interested in this ? |
Yeah, for sure. We have a bunch of code that hacks around this issue in the SymbolServer. |
Any chance we can rebase and merge this? Just ran into another issue which needs this PR or something like it to fix. |
e0ac286
to
6abca30
Compare
What is the state of this? It would be great to get this into 1.12. |
I haven't looked at this in a couple of years. :( I'm sorry I let it linger. @pfitzseb: would you be able to clean this up and bring it to merge? I think the naming question seems to have an answer above, so someone just needs to apply that and then rebase and merge? @aviatesk i don't remember everything we were talking about before, but do you have any remaining unaddressed concerns? |
This should fix the tests (and behaviour). Basically, unresolved bindings should never show up in the output, which the additional check ensures. I don't have write permissions for this repo, so I'll just post the diff here. cc @aviatesk for a sanity check :) diff --git a/src/module.c b/src/module.c
index e8ea5c7375..1292ed7cf9 100644
--- a/src/module.c
+++ b/src/module.c
@@ -992,7 +992,7 @@ JL_DLLEXPORT jl_value_t *jl_module_usings(jl_module_t *m)
}
uint8_t _binding_is_from_explicit_using(jl_binding_t *b) {
- return (b->owner != b && !b->imported &&
+ return (jl_atomic_load_relaxed(&b->owner) != NULL && b->owner != b && !b->imported &&
// Modules implicitly get all exported names from Base and Core as if they had
// written `using Base`, but we don't show those via `names()`.
// b->owner->value != (jl_value_t*)jl_base_module && b->owner->value != (jl_value_t*)jl_core_module);
diff --git a/test/reflection.jl b/test/reflection.jl
index 0ecf817ddd..e9e35b1ff4 100644
--- a/test/reflection.jl
+++ b/test/reflection.jl
@@ -188,14 +188,16 @@ let
Symbol("@test_deprecated"), Symbol("@test_logs"), Symbol("@test_nowarn"), Symbol("@test_skip"),
Symbol("@test_throws"), Symbol("@test_warn"), Symbol("@testset"), :GenericArray, :GenericDict,
:GenericOrder, :GenericSet, :GenericString, :Test, :TestSetException, :detect_ambiguities, :detect_unbound_args,
- :TestMod7648, :TestModSub9475, :TestMod7648, :a9475, :foo9475, :c7648, :foo7648, :foo7648_nomethods, :Foo7648])
+ :TestMod7648, :TestModSub9475, :TestMod7648, :a9475, :foo9475, :c7648, :foo7648, :foo7648_nomethods,
+ :Foo7648, Symbol("@__MODULE__"), :Base, :LogRecord, :(==), :(===), :TestLogger])
@test Set(names(TestMod7648, all = true, usings = true)) == Set([:x36529, :Test, Symbol("@inferred"), Symbol("@test"), Symbol("@test_broken"),
Symbol("@test_deprecated"), Symbol("@test_logs"), Symbol("@test_nowarn"), Symbol("@test_skip"),
Symbol("@test_throws"), Symbol("@test_warn"), Symbol("@testset"), :GenericArray, :GenericDict,
:GenericOrder, :GenericSet, :GenericString, :Test, :TestSetException, :detect_ambiguities, :detect_unbound_args,
:TestMod7648, :TestModSub9475, :a9475, :foo9475, :c7648, :d7648, :f7648,
:foo7648, Symbol("#foo7648"), :foo7648_nomethods, Symbol("#foo7648_nomethods"),
- :Foo7648, :eval, Symbol("#eval"), :include, Symbol("#include")])
+ :Foo7648, :eval, Symbol("#eval"), :include, Symbol("#include"), Symbol("@__MODULE__"), :Base,
+ :LogRecord, :(==), :(===), :TestLogger])
@test isconst(TestMod7648, :c7648)
@test !isconst(TestMod7648, :d7648)
end |
073b98c
to
d5b0b9c
Compare
This PR should probably be merged along with the enhancement for REPL completions, so I'll merge #42094 into this one for now. |
Add `usings` to names in REPL completions. Follow up to #42092, rest of #36529. This enables the REPL to use the names imported via `usings` in completions. --------- Co-authored-by: Shuhei Kadowaki <[email protected]>
names(m::Module)
to return the bindings that come from using
statements inside that module.using
-ed names
using
-ed namesusing
-ed names
d90359f
to
15ea438
Compare
This commit adds a new keyword argument to `names(mod)`, allowing it to return names that are `using`-ed. Additionally, as an example application of this feature, it aims to improve completion capabilities by using this functionality in REPLCompletions. Co-authored-by: Shuhei Kadowaki <[email protected]> Co-Authored-By: Sebastian Pfitzner <[email protected]>
2830737
to
0fafbc9
Compare
I'd like to replace this with #54609. |
Add parameter to
names(m::Module)
to return the bindings that come fromusing
statements inside that module.This was actually a bit trickier than I expected it to be, because there are a few oddities to consider:
Foo
, which come fromusing Foo
, are added tom
's bindings table lazily, whenever they're first referenced.->imported
, because it means the names returned fromnames(m::Module, usings=true)
would change over time as functions are called that perform the binding lookup!m->usings
list, and fetch all of their exported names.names()
currently works.all=true
? i.e. shouldnames(m, all=true, usings=true)
return names that come from Base and Core? We did writeall=true
, and we're not returning all the names... but also, it's very noisy / probably useless to return all of them.Here's a nice example that I think showcases all the edgecases:
Fixes #36529.
using
#53524