felix-hilden / sphinx-codeautolink

Automatic links from code examples to reference documentation
https://sphinx-codeautolink.rtfd.io
MIT License
58 stars 9 forks source link

Abstract the implementation #148

Open LecrisUT opened 1 month ago

LecrisUT commented 1 month ago

Would it be possible to abstract the implementation? From what I see this currently relies on ast module, but if we were to provide a similar python interface, could it work to extend to non-python source as well?

felix-hilden commented 1 month ago

Hi! That's an interesting idea for sure. I think it'd be quite a lot of work, because not only do we rely on AST, but also largely the project being importable to extract type hints. Not sure about Sphinx internals there, maybe there's something we could use if other languages report types too. What would you use it for?

LecrisUT commented 1 month ago

but also largely the project being importable to extract type hints

I could use a reference for this to understand. I thought this is still left to the predefined domain role and rely on whatever autoapi was used to extract them.

Not sure about Sphinx internals there, maybe there's something we could use if other languages report types too

For this would the language specific domains be useful, e.g. C++ (also definition). In the sense that you can assume there is a dict between an ast type and one of a sphinx domain role or a function that would translate it?

What would you use it for?

Given that there is already upstream domain and ast implementation for C/C++ I would start there, without autosphinx support if it makes sense.

felix-hilden commented 1 month ago

This whole module, starting from the top does the resolving! It's more than just linking AST to Sphinx inventories. When we use a method of a class in code, we need to determine what comes out. And maybe what you described is exactly it, I'll have to have a look later on!