JunoLab / Juno.jl

MIT License
144 stars 23 forks source link

[FR] Function -> Method discoverability of a variable #514

Open iagobaapellaniz opened 4 years ago

iagobaapellaniz commented 4 years ago

I am thinking on an enhancement for Juno I guess can help people to discover the functions at hand for some type.

As in traditional OOPLs, when one types a variable of a certain type the promt used to suggest some functions which act on that variable.

I explain the idea with a simple example and some short of code needed to implement this.

Imagine we have an x variable assigned to an Int64. image

Appart from the definition and some functions, it would be nice to show to the user a list of functions that act on/with x as one of the arguments.

I have something implemented to get the list of functions which can act on, say a 6, or "abc"

InteractiveUtils.methodswith(x::Any; supertypes = false) = 
    methodswith(typeof(x); supertypes = supertypes)
functionswith(T; supertypes = false) = 
    sort!(unique(map((x) -> getfield(x, :name), 
        methodswith(T; supertypes = supertypes))))

The user could continue typing until the desired function is found and then methodswith(Int64, f) can be call to list all the possibilities.

More discussion and more implementation details can be found in the following thread https://discourse.julialang.org/t/feature-why-not-a-functionswith-method/35409