HiPhish

HiPhish

Hello,

I know that I can get the documentation of a symbol in iex by typing h whatever, but is there a way to get this documentation programmatically? For context, I use Neovim and I would like a way of reading the documentation inside an editor buffer instead of a REPL running inside a terminal shell. I have already written info.vim which does similar thing for GNU Info documents. Neovim makes it possible to write remote plugins in Elixir, so if there is some Elixir module to get the documentation as a text string it should be fairly simple to pull off.

First 9 of 9 Posts Switch mode

emoragaf

emoragaf

Take a look at h implementation: elixir/lib/iex/lib/iex/introspection.ex at d8d89b431e197dd230ce01bc20f4656d9ef24e5c · elixir-lang/elixir · GitHub

It seems to be using Code.fetch_docs underneath

HiPhish

HiPhish OP

Thanks, that looks like what I need. I tried calling it by hand, but I get an error instead:

iex(10)> IEx.Introspection.h(:Kernel)
Could not load module :Kernel, got: nofile
iex(11)> Code.ensure_loaded(:Kernel)
{:error, :nofile}

I looked up the definition of h, but it uses macros, which I am not yet familiar with.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

:Kernel is not the same as Kernel. Kernel is the same as :'Elixir.Kernel'. Try IEx.Introspection.h(Kernel)

HiPhish

HiPhish OP

Great, that works! Code.fetch_docs(:'Elixir.Kernel') gives me structured data which I can work with. One more question, how do I specify a function? I have tried Code.fetch_docs(:'Elixir.Kernel.is_atom/1'), but I get {:error, :module_not_found}, same thing without the /1 part.

EDIT: Never mind, I need to look at the implementation of Ex.Introspection.h/1, not Ex.Introspection.h/1.

eksperimental

eksperimental

You can have a look at ExDoc source code, paritcularly to the retriever module.
https://github.com/elixir-lang/ex_doc/blob/master/lib/ex_doc/retriever.ex

Other Elixir modules of interest are:

Have fun!

eksperimental

eksperimental

You can use Kernel, no need for cumbersome and non-standard :'Elixir.Kernel'. Btw Kernel is an alias that resolves to :"Elixir.Kernel". :Kernel is just an atom.

iex(2)> :"Elixir.Kernel"
Kernel
iex(3)> :Kernel
:Kernel
axelson

axelson

Scenic Core Team

I just wanted to make sure you’re aware that there are existing ElixirLS-powered vim/neovim extension that already support fetching Elixir documentation:

But if you want to create to create this extension for learning purposes, or as an improvement (such as being lighter-weight), then please go ahead :+1:

HiPhish

HiPhish OP

Yes, I am aware of it and I’m using it, it’s a fantastic tool.

That’s the plan, I am working through the guide right now and I want to try my hands at something useful next. Plus, I prefer reading documentation in a separate buffer I can have open to the side rather than a floating window. I could have probably hacked something using the Lua API of the built-in client, but this seems more interesting. Plus it would work even without a language server running.

lukaszsamson

lukaszsamson

ElixirLS Core Team

If you are looking for something more lightweight than a full language server than you could try elixir_sense, the lib utilised by elixirLS - elixir_sense/lib/elixir_sense.ex at 28f8467a349c6ed004aac66a2e8d7020cdde2e0d · elixir-lsp/elixir_sense · GitHub

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement