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.

Showing Posts 1 to 9

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
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews