-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guess compile commands in irony-server. #270
base: master
Are you sure you want to change the base?
Guess compile commands in irony-server. #270
Conversation
Using rapidjson to read the database, and cache the database between subsequent reads. For guessing commands, path operations from boost filesystem are used. If boost filesystem isn't detected on the system, the database is disabled.
One question first. Anyway, here I notice that we have 2 new dependencies, why not use only Boost which provide a JSON parser? Also, which the big file: server/test/elisp/compile_commands.json ? This thing
tests the same thing as this thing ?
For the caching part I'm okay with the idea, for the guessing part I'm not sure. I think I would prefer the user to have the possibilities to document the mapping or have an indexer tool giving this information. The strategy you used might be an interesting default. |
Since we'll be making boost an optional dependency this change shouldn't make Irony any more complicated to use, only nicer for people with boost installed. At least that's how I see it. I didn't know boost shipped a JSON parser. I will update the pull request with it when I have the extra time (which is in short supply now).
I added a quite large JSON file because I wrote a test that checked if irony-cdb-json and irony-cdb-server returned the same result. We can remove this test if you want, but in my opinion it's always better to test more.
Yes, I agree we could do better than this but it also comes down to speed. The user shouldn't notice the time it takes to load the database when opening a new file. I've got some ideas on how to parse the sources to get more accurate header compilation options, but it might make things slower. Also, this algorithm is very accurate, I've been using it for months and haven't noticed any problem with it. |
Hi, thanks for your work. This patch was very helpful to me. It seems you may |
@dvzubarev Glad to hear that you've had use of it. I've opened a new pull request rebased on current master only requiring 1.54. |
I also got this patch with working with reasonable speed on top of gecko (the firefox web engine), which produces a 5.4mb compile_commands.json file. Looks like there's been some changes to irony-mode since the last revision that break things if you try to rebase (irony only passes the compilation db directory instead of the whole file path, which makes boost confusingly throw an underflow error since the irony mode server doesn't check the path to make sure it's a valid file), so there needs to be another patch revision to bring it up to date. |
Hi @qdot, Out of curiosity, I took a look at Firefox codebase to see how to generate a compilation database and find out a reasonable way to get header compile options. I actually found that there is a command in the Firefox build system that should do what you want without the need for irony-server's guessing, any reason not to use it?
Seems like they have these few handy commands:
@Hylen: I don't think I will ever accept the server guessing code for irony-server. I think the compile options problem is useful to other things than just irony-mode, also I think this may be something quite involved by itself that can grow bigger than the actual irony-server. It shares almost nothing from libclang, so I think this could be made a standalone tool. It would be easy to detect if the tool is available and use it in an irony-cdb backend (this I would not be opposed, I might actually use it). FYI, I have started working on a python tool to manipulate compilation databases: It's nothing too interesting for now but I implemented a command that generate a header compilation database from a compile_commands.json. For example, for irony-mode, one could do proceed as follow to generate a header compilation database:
FYI, in this tool I have taken the following approach for now for the guessing:
|
@Sarcasm I'd tried using the .clang_complete method before, it'd never really worked for me, but I could give it another shot. I wasn't really looking for the command guessing portions of the patched irony-server anyways, more loading compile_commands.json in C++. Since it's a huge file, loading and parsing it in elisp was what was making everything slow (I profiled it in emacs and the json parsing functions were something like 80-90% of the time spent during file load). That's really the only thing I need. |
Using rapidjson to read the database, and cache the database between
subsequent reads. For guessing commands, path operations from boost
filesystem are used. If boost filesystem isn't detected on the system,
the database is disabled.