JuliaEditorSupport / julia-vim

Vim support for Julia.
http://julialang.org/
Other
756 stars 94 forks source link

Documentation for packages using K #317

Closed aris-mav closed 1 month ago

aris-mav commented 2 months ago

The command K seems to work perfectly well for showing documentation of functions defined in Base Julia, but I'm not sure how to make it work for functions defined in packages. Is there a way to work around this by any chance?

ararslan commented 1 month ago

This would be rather tricky to implement since it requires an awareness of the context in which a symbol you're requesting documentation for is being used. That context is very difficult to determine accurately.

At the moment, we start a very short-lived Julia process to print the result of calling @doc on whatever was under the cursor: https://github.com/JuliaEditorSupport/julia-vim/blob/7946ce330b6287c9293aece5b14feafa1125779e/autoload/julia/doc.vim#L38

That's a reasonable solution for Base functions, though it doesn't correctly handle shadowed bindings. Consider, for example, K on an occurrence of mod inside of a function definition which has an argument called mod. You'll get the documentation for the function Base.mod, but that's not actually what you were looking at when you used K. The current solution also doesn't handle qualified calls to documented functions, e.g. Base.IteratorSize, but that could probably be fixed.

The situation is significantly more complex for package documentation, as the process used for lookup would need to load all of the packages that the file being edited is or could be referencing. You don't necessarily know what those are just from the current buffer: consider e.g. editing a file that's included by another file, and it's the latter file that's loading packages.

I'm not sure it would be feasible to implement this here without using a full-blown Language Server implementation. Notably, one exists for Julia, and it's used by the VSCode plugin. It has instructions for use with (Neo)Vim as well: https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim.

aris-mav commented 1 month ago

Thank you so much for the detailed answer, Alex. I tend to keep a separate window/buffer open with my julia repl within nvim, so I reckon the best solution might be some binding that sends "?word_under_cursor" to that repl and displays the result. I might try to work on that whenever I find some time.