-
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
Trouble setting up irony mode with company and json compilation database #137
Comments
Hi, Great to have some reports on this new compilation database plugin, I'm expecting some issues as it is used in real-world. And also because it's not much documented yet. I'm curious about where does this A few things you can do that may help debugging the issue:
If the compile_commands.json is in a separate build directory, know that you can tell irony-cdb-json about it by calling
Note that if you have already a knowledge of the flags, it could be a nice idea to create a compilation database for irony, see |
Debugger entered--Lisp error: (wrong-type-argument sequencep libclang:)
mapcar(#[(candidate) "\301�@\302�#\207" [candidate propertize irony-capf] 4] libclang:)
irony-completion-at-point()
completion--capf-wrapper(irony-completion-at-point all)
run-hook-wrapped(completion--capf-wrapper irony-completion-at-point all)
completion-at-point()
irony-completion-candidates-async(completion-at-point)
irony-completion-at-point-async()
call-interactively(irony-completion-at-point-async nil nil)
command-execute(irony-completion-at-point-async)
P.S: One small note about the project. It uses CMAKE as its build system. Its root directory, where the compilation database file is located, contains a build directory (for CMAKE) where the compile commands are given. So the actual working directory for the compile commands is the build directory. Could that affect anything? I know that you have the option to make the compilation database with CMAKE, but I tried it and it is the same result as with the malinka generate compilation database. I tried to place the database both in the build and in the root directory and point irony mode to it but nothing seemed to work. Keep getting that |
New development: I modified the project I had been using to create the compilation database to opt for using cmake itself to create the compilation database and save it in the build directory. At first I saw no differences, but I stopped getting the error. After 30-40 seconds completions started appearing! Perhaps irony was indexing the project in the meantime? I got no notice for project indexing though so I assumed the error was persisting. That leads me to suspect that if it's a Cmake project and the before:
now:
|
Okay so I think there are a few different issues (but I may be wrong). First it looks like you get the error not from You have the string/value The fact that your project is complex and the completion takes so much time may come from the fact that the compile options are wrong. libclang is unable to find all the include files or to parse them, so it cannot generate a preamble file and everything get a little bit sluggish. Irony shouldn't care much about the location of the I think the root of the issue is that either libclang cannot parse your project for some reasons or that the compile options are a little bit wrong. Can you edit the following code: Line 581 in b0923fd
From: (start-process "Irony" irony--server-buffer
irony--server-executable
"-i"
+ "-d"
"--log-file" The addition of |
When doing |
Hello and sorry for answering so late. Real life working week got to me. I just tried the things you asked at my work computer. At there I am not getting those errors but I have another more major problem. Irony-server does not even seem to start at all here. I run emacs as a server with systemd and this is how
After looking at the code I saw that calling this function
So the problem now is that no matter what I do the compilation database can not be found. As I said it is located under the And for some reason the server does not start automatically but instead I had to explicity start it as I mentioned above. I realize this is quite probably a different issue. If you would like I could open another ticket, and here we can continue discussion on the original issue which I will try to reproduce when I am back at my home computer where it first occured. Whatever you would like. |
The server starts only when needed. Right now it will start only you start asking for completion. |
So as I said I have to investigate further about what I mentioned in my last post. It's a totally different thing on a different computer. Back to the original issue. I tried it in a different project which gets the compilation database the same way, by the Malinka package. I got the same results. If I use a project with cmake > 2.85 which has CMake generate the compilation database, then completions do work. If I use the malinka generated database then I get the libclang error. This should be a strong hint that the generated database may be flawed. I always assumed it was correct since it works when it is fed to the RTAGS daemon. If that is indeed the case and since I am the author of malinka I would really like to see why so that I can fix and improve it. For the things you asked. After setting the debug mode on for the server and getting the error I see the following in the log: (Warning, it's big)
And from that alone I think I can spot what would confuse clang. For some reason the compilation database seems to contain every other source of the project for each file as compiler arguments. Let me try to address that on my side. I still wonder why it works with the Rtags daemon then though. I guess that on irony's side a more graceful way of handling such a failure would be nice with maybe an error message like the above: `libclang couldn't parse '/home/lefteris/w/refu/lang/src/front_ctx.c' |
This weekend I will do a bit of reworking of how malinka generates the databases, and also pretty print it. For now I tried a dirty fix to not include the extra source files as arguments in the command. It worked but unfortunately completions still did not work. Which lead me to finding the last incosistency between the 2 compilation databases. Relative paths. I was using relative paths to the build directory in the malinka compilation database. This is why irony mode could not find them. This cdb entry did not work with irony:
This cdb entry worked:
I think that relative paths to the build directory should be working as the example contained in clang's own page actually is one with relative paths. If you need any help to figure out why relative paths don't work feel free to ask me anything. |
I will have to look more clearly but paths should normally be expanded, see this code: Lines 207 to 208 in e5aea72
Will check your issue more clearly during the week. edit: oh you are probably not talking about the "file" entry but the include paths and things like that. There might be some errors on this side. |
I receive the same problem as mentioned in the original post above:
This happens when I try to run
Also, I am using company-irony and do not get any completions in the middle of a symbol, while I do get them perfectly after "->" or ".". Same bug? |
@pronobis: not necessarily the same bug.
This message is just due to an internal error of libclang while parsing your file. It usually comes from the code that Clang for some reasons is unable to handle (it has become a rare occurence with recent versions of Clang IMHO). If you could open another issue that would be better to keep track of the problem. |
Sounds good. |
@LefterisJP: Thinking about it, the path should be handle properly by Clang I think, because I'm adding the working directory as shown in
|
After some changes to my setup I can't reproduce it properly anymore. I still have issues with irony not picking the compilation database sometimes but it may be that it's a bit slower than I would have wanted because it does pick completions up after some time. When I find the time I will need to debug it more and see if I still get any libclang crushes under any circumstances. If not then this issue may no longer be an issue. |
irony-mode may take some time to load the completion database when you open the buffer but this is not something done in background so you would notice it if it's too long (and you wouldn't be able to perform code-completion or things like that until it's done anyway). So in theory, either the compile options are right or they aren't but it is not something that should change after some time. The issue may be somewhere else, let me know of your findings if it happens (potentially in another issue if this one is closed). |
Definitely. Thanks for your responsiveness. I really appreciate irony as a tool and want to see it improve :) |
Sarcasm, I'm running into a similar issue as LefterisJP was describing. It sounds like LefterisJP was unable to recreate the issue any longer so maybe I can help track down the issue. If my problem turns out to be unrelated I can just create a new thread. Installation: I installed company, company-irony, and irony-mode packages from Melpa. I updated my init.el to include the suggested entries for the three packages, exactly how LefterisJP listed in his first post. I built and installed irony server pointing to my homebrew installation of llvm 3.5.1 by adding the -DCMAKE_PREFIX_PATH=[path/to/llvm/3.5.1] to the cmake args. Project: Makefile project, so I used bear to generate a JSON database containing compile flags. The compile_commands.json file looks like it has a list of flags for each object as I would expect. Just like LefterisJP, I am successfully using this JSON database with RTags. When I run irony-completion-at-point-async in a project file, I get back "Wrong type argument: sequencep, libclang:" After toggling on debug on error I get a backtrace with the same contents as LefterisJP listed earlier. Here's where I start to get suspicious... When I inspect irony--compile-options (after running irony-completion-at-point-async), only the first entry from the compile_commands.json file is listed in the variable. Perhaps LefterisJP's compile_commands.json file changed due to another generation tool or from changes to his project that fixed the irony--compile-options issue. I also tested the irony-server in a bash terminal (not sure if this is relevant or helpful):
Any thoughts or help is appreciated. Thanks. |
@DanSchoppe: for now I don't think it's the same issue, let us continue here: #191 |
Thanks for sharing this package. My understanding is that |
I'm closing this issue. @egarrulo you are right, the compilation database stuff isn't ready yet to have a proper release, I need to rework it. |
Hello,
First of all I would like to thank you for making irony-mode. It seems like a really nice package that greatly enhances the C/C++ editing experience.
I am an rtags user, but wanted to combine it with irony mode so as to get nice completions. Thus I tried to use company mode and company-irony. I obtained the packages from el-get. My setup is as follows:
Nothing fancy. Just what the wikis say. I also got
(add-hook 'after-init-hook 'global-company-mode)
somewhere so that I activate company mode.I am using json compilation databases for all of my projects. I use a package that I have created to act as a glue between other emacs packages and create the json compilation database. I know that the database is valid since rtags server gets it as input and correctly navigates the projects.
So I have this json compilation named compile_commands.json in the root of the project. I suspect that irony mode actually reads it since I see something that looks like the whole project's compile flags, include directories and files when I execute
irony-cdb-menu
.But the problem is that whenever I try to use any autocomplete or anything at all, all I get is an error message:
I also tried to describe the current company backend variable and it seems to be nil. This is funny because
company-backends
list has company-irony as the first one in the list. I tried to insertcompany-irony
as the only element of company-backends but I got the same result.While debugging I tried to remove
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
from the setup. Then completion popup actually appeared but it was totally random. Seemed to have no proper source. Could the issue be with the way that irony autodetects the compilation database?Do you have any idea what may be happening? IF you need any more information about my setup I will gladly provide.
The text was updated successfully, but these errors were encountered: