tpapp / julia-repl

Run an inferior Julia REPL in a terminal inside Emacs
Other
173 stars 35 forks source link

Go to definition (M-.) #50

Open cstjean opened 5 years ago

cstjean commented 5 years ago

Thank you for this package! Is there something like M-. (aka go-to-defintion) in this package? I find that C-c C-e is not too useful when editing module code, because of course, the arguments can't be evaluated.

tpapp commented 5 years ago

Not at the moment, as it would have to query the Julia process in the background for the relevant information. PRs and suggestions are welcome, eventually I guess this should be possible with LanguageServer.

gdkrmr commented 5 years ago

This works with lsp-julia.

cstjean commented 5 years ago

Thank you for the link to lsp-julia

Here's a suggestion in line with this package's philosophy. Send this command to julia:

julia> println(methods(findfirst)); edit(methods(findfirst).ms[parse(Int, readline())])
# 7 methods for generic function "findfirst":
[1] findfirst(A::Union{AbstractString, AbstractArray}) in Base at array.jl:1661
[2] findfirst(pred::Base.Fix2{#s57,#s56} where #s56<:Union{Int8, UInt8} where #s57<:Union{typeof(==), typeof(isequal)}, a::Union{Array{Int8,1}, Array{UInt8,1}}) in Base at strings/search.jl:22
[3] findfirst(testf::Function, A::Union{AbstractString, AbstractArray}) in Base at array.jl:1742
[4] findfirst(testf::Function, A) in Base at array.jl:1735
[5] findfirst(pattern::AbstractString, string::AbstractString) in Base at strings/search.jl:104
[6] findfirst(r::Regex, s::AbstractString) in Base at regex.jl:243
[7] findfirst(A) in Base at array.jl:1652
6   # user input

If you can get the method number from emacs and send it to the julia process, then it should work.

gdkrmr commented 5 years ago

Here's a suggestion in line with this package's philosophy. Send this command to julia:

julia> println(methods(findfirst)); edit(methods(findfirst).ms[parse(Int, readline())])
# 7 methods for generic function "findfirst":
[1] findfirst(A::Union{AbstractString, AbstractArray}) in Base at array.jl:1661
[2] findfirst(pred::Base.Fix2{#s57,#s56} where #s56<:Union{Int8, UInt8} where #s57<:Union{typeof(==), typeof(isequal)}, a::Union{Array{Int8,1}, Array{UInt8,1}}) in Base at strings/search.jl:22
[3] findfirst(testf::Function, A::Union{AbstractString, AbstractArray}) in Base at array.jl:1742
[4] findfirst(testf::Function, A) in Base at array.jl:1735
[5] findfirst(pattern::AbstractString, string::AbstractString) in Base at strings/search.jl:104
[6] findfirst(r::Regex, s::AbstractString) in Base at regex.jl:243
[7] findfirst(A) in Base at array.jl:1652
6   # user input

If you can get the method number from emacs and send it to the julia process, then it should work.

That would be great to integrate with lsp-julia, so you get a list of definitions to jump to. I have no idea how to integrate this in with the different autocompletion systems such as helm and ivy.

PetrKryslUCSD commented 4 years ago

Why not ctags?

tpapp commented 4 years ago

AFAIK ctags would require that index files are pre-generated (and updated when necessary). At the same time, this information is available in the Julia image, so @gdkrmr's suggestion would be easier to do.

LSP support developed quite a bit since this issue was opened, perhaps it is time to revisit the implementation.

PetrKryslUCSD commented 4 years ago

This, presumably, might work also with the user's own files?