Open UberLambda opened 9 years ago
For some reason it seems like the hook isn't called, I don't know why just yet.
What Emacs version do you have?
Okay, the hook isn't called at home for me (Emacs 24.5.1) but it is at work (older version). I will take a look.
Be careful in your configuration:
(defun my-load-irony-options()
(irony-cdb-json-add-compile-commands-path (projectile-project-root)
(concat (file-name-as-directory "build")
"compile_commands.json"))
I'm not sure if duplicates are cleaned up properly, I will have to take a look but I plan on changing irony-cdb a bit.
Yeah, I had a FIXME
comment about that... does simply clearing irony-cdb-json--project-alist
reset the list, or is extra work needed to reset it?
I checked, I'm using add-to-list
so duplicate are taken care of by irony.
I was wrong, even with Emacs 24.5.1 it works for me, I wasn't on master and I had some weird configuration (to test what I'm working on) but once the configuration restored it works fine.
After looking at your configuration more carefully I'm wondering if you could try to replace the following in your configuration:
;; Add "../build" (relative to the projectile root directory) of Cxx projects
;; as the path where to find "compile_commands.json", then load irony's options.
(defun my-load-irony-options()
(irony-cdb-json-add-compile-commands-path (projectile-project-root)
(concat (file-name-as-directory "build")
"compile_commands.json"))
(irony-cdb-autosetup-compile-options))
;; Reload and apply the Clang flags each time an irony buffer is opened
;; FIXME: the json's dir gets added every time, but the list never gets reset...
;; FIXME: this should run on 'irony-mode-hook, but it does not seem to work
;(add-hook 'irony-mode-hook 'my-load-irony-options)
(add-hook 'c-mode-hook 'my-load-irony-options)
(add-hook 'c++-mode-hook 'my-load-irony-options)
(add-hook 'objc-mode-hook 'my-load-irony-options)
By this:
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
Then you can call irony-cdb-json-add-compile-commands-path
manually if the path isn't already set.
Can you tell me if this work?
I'm not sure it's safe to call the projectile function in irony mode hook, how can you guarantee the order of initialization of the minor mode? If for some reasons something in projectile errors when projectile isn't yet initialized, (irony-cdb-autosetup-compile-options)
may not be called for example.
I tried removing the custom callback and calling irony-cdb-json-add-compile-commands-path
from the M-x menu manually, using ido-mode to select first the build directory and then compile_options.json
's location.
Irony now doesn't seem to load compile_options.json
at all for some reason (atleast M-x irony-cdb-menu
tells me there is no completion database)...
Can you try that: https://github.com/Sarcasm/irony-mode/issues/190#issuecomment-93062550
Sure.
Output before adding compile_commands.json
with irony-cdb-json-add-compile-commands-path
:
Making completion list... [2 times]
check-compile-options: Symbol's function definition is void: irony-cdb-json--ensure-project-alist-loaded
In include /home/paolo/gamedev/bw/core/src/bw/core.h
After adding compile_commands.json
:
Making completion list... [2 times]
In include /home/paolo/gamedev/bw/core/src/bw/core.h
E: failed to locate compilation database
I've setup irony with a
.clang_completer
file, and I have the following run by Emacs at startup:If I open a c-mode buffer, though, M-x
irony-cdb-menu
shows that no completion database is loaded the first time, even thoughirony-mode
is enabled and, as such,irony-mode-hook
should have run already. M-xdescribe-variable
irony-mode-hook
seems to be correct, since all of the three callbacks defined in the config snipped above seem to be present.Running
irony-cdb-autosetup-compile-options
(and restarting FlyCheck to refresh the error list) by hand seems to fix this issue.