Language Server Tool to Navigate Across PackedFunc FFI for IDEs like VSCode and Emacs

Right now TVM relies heavily on the PackedFunc mechanism to register C++ APIs to the frontend. Existing IDE will be able to goto definition within the same language, but not necessarily across languages.

On the other hand, it is not too hard logically to find the definition point from the python or Registry::Get(), by running a grep on TVM_REGISTER_GLOBAL and matches the related name.

One way to bake that into the IDE is to provide IDE extensions. For VSCode, there is a callback API (registerDefinitionProvider and registerReferenceProvider) to register the navigation APIs, reference code can be found in t This way we might be able to nagivate across the code boundary more easily in the VSCode.

This seems would be a fun hacking project. Open this thread to see if this is of interest the community, and anyone want to hack a bit :slight_smile:

cc @jroesch who also mentioned similar ideas


This would be SUPER useful! Looking forward to seeing it happen.

Hope it also works on emacs …

1 Like

I use emacs for most of my development :slight_smile: unfortunately I am not familiar with elisp, my guess is that similar thing can be hacked up but will need a different solution, unless we adopt some common interface(there is a language server protocol which might be overkill) given it is only a grep and find

OK i did some hacks, it turns out to be a harder than i first thought…

Anyway, here is an initial version It contains a language server, and a vscode client, you can try it out in vscode.

Because most implementations are done through the common language server protocol, we might be able to use it in other IDEs, by make use of emacs plugins that talks to the language server.

I am a complete novice to this area(code analysis, typescript, language server) so please feel free to jump in and help if it can be useful.


ok I’m using emacs lsp-mode, will try if it can be used from emacs

1 Like

Instruction for emacs is added


wow great! I can do M-. (xref-find-definitions) on _min_value and it worked out of the box! I didn’t have to set lsp-workspace-folders-add.

Great, in that case I guess lsp-mode automatically guess the root correctly.

Anyway, right now the feature only contains the find def from py to cxx.

I find it is interesting to add project specific analysis that can be minimum and enhance the IDE in this way.

Would love to see how will the such kind of IDE enhancements benefit our development and code navigation

I’m playing with this, it is so much fun :slight_smile: I encourage everyone to try it (but be sure to fetch my PR at, which enables fallback to pyls)

It’s great to be able to do things like this without messing with elisp or typescript.

VS code extension works beautifully! I’ve also tested that the extension can be compiled locally once and install to a remote server via Remote SSH, although fft_navigator must be available on the remote server to make it work.

I would also recommend directly installing the package so that we don’t need to setup PYTHONPATH.

improvements(instructions and features) are more than welcomed. The PYTHONPATH is mainly used to ease development purposes.

I made some more hacks, the latest set of improvements are here Feel free play with it and enhance more to add features that might helps the development

1 Like

This could also be of interest to MXNet or PyTorch dev. Supporting MXNet seems straightforward, but pytorch generates C++ code from templates during build, so it requires source build be done beforehand.

To make it easier to support other projects, we want to separate TVM-specific component into one place and make BaseServer dispatch into project-specific handlers.

I just did anothe refactor to isolate the project specific part into a folder. I will stop adding major changes at this point, I think it should be pretty easy to add new ffi dialects, and enhance the project a bit further to allow configuration of things like path to scan and so on, feel free to add features that you think are good

Looks great, thanks. Will add mxnet dialect and possibly torch too.

1 Like

Is there anyone who is willing to share his/her experience installing ffi-navigator either in CLION or VS studio?

For some reason, I failed to follow instructions provided here:

First, I tried to install it under my anaconda using following command inside ffi-navigator folder. It did not showed up on my list of packages of my anaconda environment.

python setup install --user

Second, I tried to install it on my VS studio, but I failed to find “%USERPROFILE%.vscode\extensions” folder on my windows machine. I am sure my %userprofile% is /my_username/ under users. But there is no .vscode folder.


If you just want to use it instead of development, you can install the extension via VSCode marketplace, and then pip install ffi_navigator. It doesn’t support CLion yet and currently no plan for it.

@comaniac – thank you very much, but VSCode marketplace does not show ffi-navigator. I did searched all combinations like ffi navigator, ffi, …etc. Nothing shows up.

1 Like