Finding functions

One issue I have with Julia is remembering the name of functions and what they do. In a typical OOP language and IDE/editor typing the name of an object and then the dot character a pop-up window will produce a list of all available functions and their documentation. In VS Code is there some facility to help with this issue?

2 Likes

If I understand correctly, this is a quite general problem given how multiple dispatch creates a large number of possible operations on a given type. I remember reading a discussion about the same issue here:

It’s already a few years old, so I’m not sure if there are some new developments in VSC since then, but maybe you find methodswith helpful.

Also just found this (haven’t looked at the suggestions in detail yet, but sounds like it could be usefule as well):

2 Likes

Also note that entering a word in quotes within the help mode (which triggers the InteractiveUtils.apropos function) gives you a list of all the methods in whose docstrings said word appears.

6 Likes

The problem is that one may not even know what function name to look for but only that he wants to find a function that does something specific and it is applicable to a datatype of interest.

Perhaps, an AI-based search system could do the job using as input the functionality a user is looking for (typed words) and the datatype of interest, using for the search the available documentation.

1 Like

That’s why I like apropos: if your function does “something specific”, the something specific may not be in the function name but it has more likelihood of popping up in the function docstring

1 Like

– and in which package is it contained :slightly_smiling_face:

Here, asking the question is probably currently the best way. But you are right, this is the case where AI could be very helpful.

1 Like

I believe @xgdgsc has a working proof-of-concept of postfix completion, which lets one still use the dot syntax for autocomplete. See Allowing the object.method(args...) syntax as an alias for method(object, args ...) - #218 by xgdgsc. Last I checked, they were still trying to upstream it into the VS Code extension and Julia language server.

4 Likes

That completion user interface is quite unintuitive, it seems like it would completely confuse anyone who doesn’t know about this specific feature. Wouldn’t it be all-around much better to have a new window pop up or something like that?

Ever since Julia 1.8 (julia#38791 by @tim.holy), you can type ??(object, <tab> and it will list methods that take that object type as a first argument.

You can also use methodswith(typeof(object)) to list all methods that take any argument of that type (whether or not it is the first argument).

11 Likes

Please, do not. I still hate R for forcing our lab servers to install a full graphic environment just so someone can select the mirror during the first run.

1 Like

I’m talking about the proposed VS Code PR. Pretty sure that Code requires a graphical environment anyway.

I had high hopes when I read that, but in many cases it seems pretty useless. For example, I have a Dict{String, Any} (the result of ArgParse.parse_args()), and I wanted to see what methods are available for getting stuff out of it. Here’s what I see:

help?> ?(args
rem(x, y, ::RoundingMode{:FromZero}) @ Base div.jl:103
rem(x, y, r::RoundingMode{:Nearest}) @ Base div.jl:100
rem(x, y, ::RoundingMode{:Up}) @ Base div.jl:99
rem(x, y, ::RoundingMode{:Down}) @ Base div.jl:98
rem(x, y, ::RoundingMode{:ToZero}) @ Base div.jl:97
rem(a::T, b::Base.MultiplicativeInverses.MultiplicativeInverse{T}) where T @ Base.MultiplicativeInverses multinverses.jl:168
getproperty(x, f::Symbol, order::Symbol) @ Base Base.jl:58

... 287 lines total ...

reduce(op::OP, x::SentinelArrays.ChainedVector) where OP @ SentinelArrays ~/.julia/packages/SentinelArrays/1kRo4/src/chainedvector.jl:781
reduce(op, A::AbstractArray; kw...) @ Base reducedim.jl:406
StepRange(start::T, step::S, stop::T) where {T, S} @ Base range.jl:379

Most of that stuff is decidedly non-useful to use on this Dict object. Maybe it’s a useful technique on a much more focused type, but it seems like we’d still get caught in the driftnet of methods whose first argument is untyped.

Is there a better technique for using this capability effectively?

1 Like

Yeah, it might be more useful to filter out methods that match only because they are untyped (Any) arguments, also suggested by @tim.holy here.

1 Like

Yes, or perhaps to use a ranking system to surface the methods that are most likely to be applicable and only show the first n results by default?