RFC: Tab completions that are sensitive to already specified function arguments

I wanted to get some discussion going on what helper tools people want / need to make coding, especially when interactively analyzing data, more enjoyable and efficient. I believe that Julia with its introspective abilities can do more in this regard.

For example, I like propertynames because authors can enhance what dot completion can do for the user. But there are many other things where more could be suggested for tab completion etc. I know this is often a question for packages like Juno but at the same time, maybe it’s helpful to offer simple packages that help authors include this functionality themselves instead of relying on third parties. Maybe a lot of these things can live in something like SuggestionsBase or TabCompletionBase etc.

In RStudio for example, when operating on dataframes many functions accept column names that look like variables. These variables already get suggested for tab completion while typing the function, once the dataframe argument is specified. Of course, Julia doesn’t allow for variable names to be interpreted only inside functions like in R, but the same would work with symbols for column names.

This could be implemented by specifying a function that filters the workspace for suitable objects and displays their variable names. I know that this is already done to some degree, but it is not implemented by package authors like with propertynames.

Imagine if instead the author could specify with simple functions with what rules suitable variables can be determined, and something like Juno would only call this function. Example:

SuggestionsBase.suggest(f::typeof(plotdataframefunc), df::DataFrame, arg::Val{2})
    # arg 2 of this function is one of the column names if arg 1 is a dataframe
    names(df)
end

SuggestionsBase.suggest(f::typeof(plotdataframefunc), arg::Val{3})
    # arg 3 of this function is one of these symbols for plotting, this does not need a dataframe in the first position for completion
    [:cross, :square, :circle]
end

What do you think about this idea, or are there others that you think would work better? What other functionality would be useful? Basically I’m all for suggesting and pre-filtering as much as possible if we know already what people are going to do in 99% of cases. Especially if there’s a known list of allowed parameters, like in the second example.

1 Like

I love the idea of having better completions like this.


I believe the stuff in the REPL is extensible.
codes here https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/src/REPLCompletions.jl

if it isn’t it should be fixed so it is.

Example of use more generally is how IJulia invokes it:


and Juno:

So rather than in Juno, or IJulia or a new SuggestionBase.
I think extending the REPL stdlib functionality is where this should live.

Thanks for the hint to the existing REPL functions, I’ll have to take a more thorough look before I can say whether they’d be suitable for what I’m envisioning.

@pfitzseb have you maybe come across this type of completion before, that is context dependent on an already specified argument, like a dataframe in first position? As I’m using Juno I’d be interested in a solution that works there as well.