Most modern IDEs support find function definition within the same language(e.g. python or c++). However, it is very hard to do that for cross-language FFI calls. While solving this general problem can be very technically challenging, we can get around it by building a project-specific analyzer that matches the FFI registration code patterns and recovers the necessary information.
This project is an example of that. Currently, it supports the PackedFunc FFI in the Apache TVM project. It is implemented as a language server that provides getDefinition function for FFI calls and returns the location of the corresponding C++ API in the TVM project. It complements the IDE tools that support navigation within the same language. We also have preliminary support for MXNet, DGL, and PyTorch, so we can do goto-definition from Python to C++ in these projects too.
Install python package
pip install --user ffi-navigator
Add the following configuration
(lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection '("python3" "-m" "ffi_navigator.langserver")) :major-modes '(python-mode c++-mode) :server-id 'ffi-navigator :add-on? t))
If you use eglot instead, check out this PR. eglot does not support multiple servers per language at the moment, the PR above contains a workaround.
It should be straightforward to add support for other editors or IDEs that have a LSP client implementation. Please refer to this site for the availability of clients.
Since ffi-navigator is intended to be used with other general purpose servers such as pyls, your LSP client needs to be able to talk to multiple servers per language. If your client does not have such feature, check out this PR and the discussion there for a workaround. This branch has fallback to pyls and it is always kept up to date with the master branch.
_type_keystring on the c++ side.
c10::RegisterOperators().op("quantized::conv2d", ...) (cpp)
m.def( "_jit_script_class_compile", ...) (cpp)
For developing the python package locally, we can just make sure ffi_navigator is in your python path in bashrc.
Add your FFI convention to dialect namespace.