Navigating in large modules

Regardless of the language when I open a module's source for the first time I look for two things:

  • Public API
  • Entry points of the API (which functions/methods are called first by the
    importing modules)

In C I look for the header file, in Haskell I look for the export list. In Rust there isn't an easy way to do this without editor/IDE support, and so far I'm unable to configure my editor (neovim) to help with this so I'd like to ask how people do this.

I think what would help is a tree view of items in the current module that can filter non-pub stuff. Ideally it should work without manual pre-processing (e.g. generating tags).

Does something like this exist? Any pointeres would be appreciated. I'm mainly a neovim user, but I'd be happy with a VS Code solution as well. One thing to note is that I'm planning using this on rustc source, so I think RLS/rust-analyzer based solutions may not work.

Thanks

1 Like

Have you tried looking a the generated rustdoc (cargo doc) ? It should filter out any non-pub entity for you, and generally has a better signal-noise ratio than source code for quickly enumerating what the public APIs are.

EDIT: Ah, not sure if this will work on the rustc source though. That beast has a rather nontrivial build system.

4 Likes

https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ helped me a lot while I was figuring out how to use compiler APIs, even though it is configured to include private items (as it's built mainly for compiler devs). The compiler is split into many crates, which means most of the items are public anyway.

If you want rustc's rustdoc without private items, you can try removing this line and run ./x.py doc src/librustc.

1 Like

I am using neovim with coc and coc-rls - works fine for me. Jumping to declaration works fine even in std (didn't actually check for external crates, but suggestions work with them so I don't see reason why this wont), also listing symbols is possible with this plugin. The issue with this plugin is that its popups tends to looks awfully on themes which doesn't support it directly (for now I found one theme which looks nice with coc out of the box, but I managed to configure the theme I used before easly in like 15mins so this is not huge deal). Also autoformating and doc-comment preview looks really nice with it. Enchanting it with markdown plugin makes its joc nicely.

1 Like

Interesting, I thought coc is for code completion. I just installed it with coc-rls, but I still have no idea how to list public API of a module. I checked its documentation (coc.txt) but no lock. What am I missing?

That's helpful, thanks.

Actually listing of full API is someting I also cannot find, when I was writing this I was thinking about "CocList symbols", but it's not very helpfull as long as it doesn't prefix symbols with their modules, my bad.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.