universal-ctags / citre

A superior code reading & auto-completion tool with pluggable backends.
GNU General Public License v3.0
320 stars 26 forks source link

How to find definition after jump to the third-party library file? #155

Open zhongweiy opened 1 year ago

zhongweiy commented 1 year ago

Hi, there,

I have an issue: after jumped to a third party file (say a system include dir), how can I find further definition in that file?

the default emacs tags has this feature as described:

"For example, if you are working on a program that uses a library, you may wish to have the tags tables of both the program and the library available, so that Emacs could easily find identifiers from both." at https://www.gnu.org/software/emacs/manual/html_node/emacs/Select-Tags-Table.html.

AmaiKinono commented 3 months ago

Hi, and sorry for the late response.

We have 2 ways to do this.

Use tags backend

First, you need to tag the system include dir together with your project. Say you are using the default configuration of Citre, then when creating a tags file by citre-update-this-tags-file or citre-create-tags-file, you'll see this in the buffer that lets you edit the options:

-R
# Add dirs/files to scan here, one line per dir/file. Leave this
# empty to scan the whole directory.

Add your project root (.) and system include dir (/usr/include/). /usr/include/ will generally be very slow to tag, so you may only want to add some files/subdirs from it.

Then you should be able to jump from your project to /usr/include/. If you want further jumping when inside /usr/include/, create a tags file for it and let Citre use it. We have an example in the user manual, but you could also call citre-create-tags-file in /usr/include/, and maybe store the tags file into the global cache directory (~/.cache/tags/ by default).

Use eglot backend

Citre now has an eglot backend, and language servers should be able to do this. I've tried in a python file (using pylsp), peeking a built-in function definition in my own project works fine. I have no experience with C/C++, but this seems to explain how to setup clangd to find system headers.