clang-tags icon indicating copy to clipboard operation
clang-tags copied to clipboard

Add an `isDefn` field to the tags table in the database (and fix a warning)

Open nrnrnr opened this issue 9 years ago • 2 comments

This patch extends the sqlite database with a new field isDefn, which is populated by calling the libclang API function

unsigned clang_isCursorDefinition (CXCursor)

A potential issue with this patch is that the database is not versioned, and if the new server is run against an old database, things silently fail. I don't know if a return code from sqlite is not being checked or exactly what the issue might be.

Ideally an API version number would be stored in the database and if the server detects an old database, a new column would be added (and perhaps all the tags entries removed). Unfortunately I don't know nough sqlite to make this happen. But if you want to pursue it, I can ask for help.

I also don't know how to extend the internal unit tests to test for this case. But 'make test' continues to pass, and I have eyeballed a database for my application and the results look good!

The patch also fixes a compiler warning.

nrnrnr avatar Dec 07 '15 22:12 nrnrnr

Thanks!

I'll try your patch and merge it as soon as I can.

We should also think about the use of such a field. Is it destined to stay hidden in the database, or do you have an idea how the information could be brought to the user?

As for SQL schema changes between versions, you're right in that clang-tags should at least detect problems, so that users can delete the database and let it be rebuilt. I'm not an expert about such things; I'll try to look how this is traditionnally done in modern projects.


_(Related to #23)_

ffevotte avatar Dec 08 '15 08:12 ffevotte

In my project, here's how the information will be brought to the user: if you click on a use, you are linked to the declaration (isDecl == 1 && isDefn == 0). If you then click on the declaration, you are brought to the definition (isDefn == 1). For identifiers that have only a definition and no declaration, clicking on the use goes to the definition in one step.

I imagine M-. in emacs could work the same way, but my emacs skills are poor.

nrnrnr avatar Dec 08 '15 17:12 nrnrnr