Skip to content

irony-cdb-autosetup-compile-options not called by irony-mode-hook #195

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

Open
UberLambda opened this issue May 5, 2015 · 9 comments
Open

Comments

@UberLambda
Copy link

I've setup irony with a .clang_completer file, and I have the following run by Emacs at startup:

; Enable irony mode for c-family files
(add-hook 'c-mode-hook 'irony-mode) ; For better flycheck/ac C support
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

; Let irony source autocompletions when a buffer is opened.
; Also, make sure to autosetup the Clang flags.
(defun my-irony-mode-hook ()
  (define-key irony-mode-map [remap completion-at-point]
    'irony-completion-at-point-async)
  (define-key irony-mode-map [remap complete-symbol]
    'irony-completion-at-point-async))

(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)

; Enable irony's flycheck checker
(add-hook 'flycheck-mode-hook #'flycheck-irony-setup)

; Enable irony's autocompletion
(defun my-ac-irony-setup ()
  (yas-minor-mode 1)
  (auto-complete-mode 1)

  (add-to-list 'ac-sources 'ac-source-irony)
  (define-key irony-mode-map (kbd "M-RET") 'ac-complete-irony-async))

(add-hook 'irony-mode-hook 'my-ac-irony-setup)

If I open a c-mode buffer, though, M-x irony-cdb-menu shows that no completion database is loaded the first time, even though irony-mode is enabled and, as such, irony-mode-hook should have run already. M-x describe-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.

@Sarcasm
Copy link
Owner

Sarcasm commented May 5, 2015

For some reason it seems like the hook isn't called, I don't know why just yet.

What Emacs version do you have?

@UberLambda
Copy link
Author

GNU Emacs 24.5.1


If it is of any help, I uploaded my .emacs.d here. More specifically, irony settings are in this file.

@Sarcasm
Copy link
Owner

Sarcasm commented May 6, 2015

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.

@UberLambda
Copy link
Author

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?

@Sarcasm
Copy link
Owner

Sarcasm commented May 7, 2015

I checked, I'm using add-to-list so duplicate are taken care of by irony.

@Sarcasm
Copy link
Owner

Sarcasm commented May 7, 2015

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.

@UberLambda
Copy link
Author

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)...

@Sarcasm
Copy link
Owner

Sarcasm commented May 8, 2015

Can you try that: #190 (comment)

@UberLambda
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants