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

Smarter REPL completions II #52661

Open
pannous opened this issue Dec 29, 2023 · 7 comments
Open

Smarter REPL completions II #52661

pannous opened this issue Dec 29, 2023 · 7 comments

Comments

@pannous
Copy link

pannous commented Dec 29, 2023

Intention: see all properties / fields / functions applicable to object :

julia> y="hello"
julia> y.[TAB]

Result: No completions

Expected: size, length, substring, reverse, ...

PS: The following already works in Version 1.10.0 :

julia> x = 3 + 4im;

julia> x.[TAB][TAB]
im re  // OK
@jakobnissen
Copy link
Contributor

The reason this doesn't work is that in Julia, functions are not accessed using the dot syntax. So, you can only get the fields this way.

To get methods that apply to an object, you can write ?(my_object<TAB>.

@pannous
Copy link
Author

pannous commented Dec 29, 2023

Understood, however the current approach seems highly unergonomic, unless I'm missing how to not search the whole Terminal display history for 'startswith' if one wants to see the parallel of y.startsw[TAB]

Of cause upon selection the function would need to be prefixed:
y.startsw[TAB][TAB] => startswith(x,

Unless julia adopted the honorable nim approach of treating a.b() and b(a) as equivalents.

@jakobnissen
Copy link
Contributor

Unless julia adopted the honorable nim approach of treating a.b() and b(a) as equivalents.

That'd be a rather large design change to the Julia language, when the language has already stabilized. That's not going to happen.

However, you're right that there is no way to autocomplete the methodswith search in the REPL. E.g. it would be nice to have:

julia> startsw?(y<TAB>
startswith(s)
startswith(s::AbstractString, r::Regex)
[etc.]

@jakobnissen jakobnissen reopened this Dec 29, 2023
@PallHaraldsson
Copy link
Contributor

PallHaraldsson commented Dec 29, 2023

Intention: see all .. functions applicable

It's a bit of a problem how many apply, even just for the string type. And apply, but not always, as with BigFloat.

Expected: size, length, substring, reverse, ...

Yes, ideally, somehow, and I checked now for the first time with ?(my_object. and the list is huge with what e.g. applies...:

HTML(content::T) where T @ Base.Docs docs/utils.jl:30
IOBuffer(str::String) @ Base strings/io.jl:308

but also:

__precompile__(isprecompilable::Bool) @ Base loading.jl:1705
abs2(::Missing) @ Base missing.jl:101
abs2(x::Bool) @ Base bool.jl:154

and many more false positives (am I seeing the full list of functions?). I suppose just a bug that could be easily fixed (or I'm "using it wrong"?).

Unless julia adopted the honorable nim approach of treating a.b() and b(a) as equivalents.

I'm not sure that's a good idea, promoting two styles, but BECAUSE:

functions are not accessed using the dot syntax

I see no issue with allowing the former a.b for completion purposes, and whey you choose it changes to the latter, also teaching people coming from OOP languages.

FYI. You CAN also do e.g. for yet an alternative syntax:

julia> x = y |> l # looking up length or e.g. lstrip, I get a reasonably small list this way.

It's not ideal, I'm not sure why I get e.g. log, log10, log1p, log2, probably the type totally disregarded (only looking at if one argument).

Another improvement could be case-insensitive search, to get e.g. LazyString, thaugh less useful seeing e.g. LinRange that would never apply, for strings.

It's understandable that BigFloat and BigInt are completed for strings, since the type matches, they for most contents it does not... I don't really expect completion to match type and content, though it might be awesome...

Should not match:
LinRange(start, stop, len::Integer) @ Base range.jl:580

possibly, except drop at least all deprecated, and show at least as one entry?:

BigFloat(x::AbstractString, r::RoundingMode; precision) @ Base.MPFR mpfr.jl:310
BigFloat(x::AbstractString, r::Base.MPFR.MPFRRoundingMode; precision) @ Base.MPFR mpfr.jl:300
BigFloat(x::AbstractString; ...) @ Base.MPFR mpfr.jl:300
BigFloat(x, prec::Int64) @ Base deprecated.jl:103
BigFloat(x, prec::Int64, rounding::RoundingMode) @ Base deprecated.jl:103

@PallHaraldsson
Copy link
Contributor

PallHaraldsson commented Dec 29, 2023

For your example I would yes, want to get all startswith variants (but only when that specific), startswith(s) isn't one of them:

startswith(s::AbstractString, r::Regex) @ Base regex.jl:320
startswith(a::Union{SubString{String}, String}, b::Union{SubString{String}, String}) @ Base strings/util.jl:58
startswith(a::AbstractString, b::AbstractString) @ Base strings/util.jl:21
startswith(str::AbstractString, chars::Union{AbstractChar, Tuple{Vararg{AbstractChar}}, Set{<:AbstractChar}, AbstractVector{<:AbstractChar}}) @ Base strings/util.jl:30

But when competing e.g. st only get startswith, stat, string, strip, not all variants of each with type info.

@pannous
Copy link
Author

pannous commented Dec 29, 2023

The |> trick works great, thanks.

julia> x |> sta [TAB]
stack
stacktrace
startswith
stat

Now the only thing left would be to adopt this for the dot

when you choose it changes to the latter, also teaching people coming from OOP languages.

Exactly!

@jakobnissen
Copy link
Contributor

Ok, so let's make a list of things that can be improved:

  • sta?(x<TAB> doesn't work to autocomplete sta, but that would be nice
  • ?(x<TAB> shows false positives, including ::Any methods, despite the documentation explicitly saying that these should be hidden

Anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants