Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
901 stars 98 forks source link

Company: An error occurred in auto-begin #442

Open junkudo opened 6 years ago

junkudo commented 6 years ago

Hey, Having some trouble getting irony mode working on this machine. I'm getting this error when I invoke company-irony directly in my file :

Company: An error occurred in auto-begin
Buffer xxx.cpp has no process
user-error: Cannot complete at point

Here's my init.el:

;; company-mode
(require 'company)
(add-hook 'after-init-hook 'global-company-mode)

;; irony
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

;; If you want to enable tab-completion with no delay use the following:
(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)

;; company-irony
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(setq company-backends (delete 'company-semantic company-backends))
(eval-after-load 'company
  '(progn
     (add-to-list 'company-backends 'company-irony)))

;; Tab completion
(setq company-idle-delay 0)
;; ==========================================
;; (optional) bind TAB for indent-or-complete
;; ==========================================
(defun irony--check-expansion ()
  (save-excursion (if (looking-at "\\_>") t (backward-char 1)
                      (if (looking-at "\\.") t (backward-char 1)
                          (if (looking-at "->") t nil)))))
(defun irony--indent-or-complete
  () "Indent or Complete" (interactive) (cond ((and (not (use-region-p)) (irony--check-expansion)) (message "complete")
                                               (company-complete-common)) (t (message "indent")
                                                                             (call-interactively 'c-indent-line-or-region))))
(defun irony-mode-keys () "Modify keymaps used by `irony-mode'."
  (local-set-key (kbd "TAB") 'irony--indent-or-complete) (local-set-key [tab] 'irony--indent-or-complete))
(add-hook 'c-mode-common-hook 'irony-mode-keys)

I can invoke my server manually and it seems to be working

$~/.emacs.d/irony/bin/irony-server --version
irony-server version 1.1.0
clang version 4.0.0 (tags/RELEASE_400/final)

Let me know if there's anything obviously wrong!

Sarcasm commented 6 years ago

What happens if you call M-x completion-at-point RET?

struct Foo
{
  int foobar;
  int foobaz;
};

void f(const Foo&foo)
{
  foo.| // cursor here
}
junkudo commented 6 years ago
 process-live-p: Buffer xxx.cpp has no process
Sarcasm commented 6 years ago

Same issue with M-x irony-version RET?

junkudo commented 6 years ago

Nope. That works: irony version: 1.1.0

Sarcasm commented 6 years ago

Hum, I have no clue for now, maybe it is a recent change, and you could try the version from MELPA stable. Or you can you try to get a stacktrace with M-x toggle-debug-on-error RET.

junkudo commented 6 years ago

What version did you have in mind? The MELPA stable versions are 1.1.0.

Sarcasm commented 6 years ago

I was thinking about testing this 1.1.0 version.

junkudo commented 6 years ago

Here's the stack trace if it's of any use to you. M-x company-irony RET :

1  Debugger entered--Lisp error: (error "Buffer jun.cpp has no process")
2    process-status(nil)
3    process-live-p(nil)
4    irony--get-server-process-create()
5    irony--unsaved-buffers-tasks()
6    irony--complete-task(nil 78)
7    irony--candidates-task(nil 78 "" case-insensitive)
8    irony-completion-candidates-async(#[257 "\300\301^B!!\207" [#[257 "\300^A\240\207" [(trash)] 3 "\n\n(fn RESULT)"] company-irony--make-candidates] 4 "\n\n(fn CANDIDATES)"] "" case-insensitive)
9    #[257 "\301\302\303\304\305\306^F^F!\307\"\310\311%\300\312 #\207" ["" irony-completion-candidates-async make-byte-code 257 "\300\301^B!!\207" vconcat vector [company-irony--make-candidates] 4 "\n\n(fn CANDIDATES)" company-irony--g$
10   company--force-sync(company-call-backend-raw (candidates "") company-irony)
11   company-call-backend(candidates "")
12   company--fetch-candidates("")
13   company-calculate-candidates("")
14   #[0 "\n\203   ^@\nC\202\n^@^K\211\205\207^@\211@\300^A9\204^\^@\306^B!\203(^@\307^B!\205,^@^A\310!\202,^@\311^B\310\"\240\210\300@\203\200^@\312\300@!\203z^@\313\300@!^T\211^R\301\314\f!\240\210\301@:\204c^@^M\203U^@\315\316!\210\3$
15   funcall(#[0 "\n\203   ^@\nC\202\n^@^K\211\205\207^@\211@\300^A9\204^\^@\306^B!\203(^@\307^B!\205,^@^A\310!\202,^@\311^B\310\"\240\210\300@\203\200^@\312\300@!\203z^@\313\300@!^T\211^R\301\314\f!\240\210\301@:\204c^@^M\203U^@\315\31$
16   company--begin-new()
17   company--perform()
18   #[0 "\301 \210^H\207" [company-candidates company--perform] 1 "\n\n(fn)"]()
19   company-auto-begin()
20   company-manual-begin()
21   company-begin-backend(company-irony)
22   company-irony(interactive)
23   call-interactively(company-irony record nil)
24   command-execute(company-irony record)
25   execute-extended-command(nil "company-irony")
26   call-interactively(execute-extended-command nil nil)

M-x completion-at-point RET :

1  Debugger entered--Lisp error: (error "Buffer jun.cpp has no process")
2    process-status(nil)
3    process-live-p(nil)
4    irony--get-server-process-create()
5    irony--unsaved-buffers-tasks()
6    irony--complete-task(nil 78)
7    irony--candidates-task(nil 78 "" exact)
8    irony-completion-at-point()
9    completion--capf-wrapper(irony-completion-at-point all)
10   run-hook-wrapped(completion--capf-wrapper irony-completion-at-point all)
11   completion-at-point()
12   call-interactively(completion-at-point record nil)
13   command-execute(completion-at-point record)
14   execute-extended-command(nil "completion-at-point")
15   call-interactively(execute-extended-command nil nil)

Do you recommend trying older versions to try to get it to work?

Sarcasm commented 6 years ago

Do you recommend trying older versions to try to get it to work?

Yes, 1.1.0 from MELPA stable at least.

Did you restart your Emacs since you have been noticing this issue?

What does M-: irony--server-process RET prints? Does it still bug after you do M-: (setq irony--server-process nil) RET?

junkudo commented 6 years ago

Yes, 1.1.0 from MELPA stable at least.

Aren't I already using irony version 1.1.0 or am I misunderstanding the suggestion?

Did you restart your Emacs since you have been noticing this issue?

Yes I have.

What does M-: irony--server-process RET prints?

M-: irony--server-process RET returns nil.

Does it still bug after you do M-: (setq irony--server-process nil) RET?

Yes

Sarcasm commented 6 years ago

Aren't I already using irony version 1.1.0 or am I misunderstanding the suggestion?

The non-stable versions of MELPA has 1.1.0 + changes from the master branch, soon it will be called 1.2.0, but there is the 1.0.0 from MELPA stable, which is really the tag 1.1.0. The 1.1.0, now 1.2.0, is just the current state of the git repository but it's a moving version different from the one on MELPA stable.

junkudo commented 6 years ago

How do you know which 1.1.0 version I have?

Sarcasm commented 6 years ago

There are multiples methods, but you can take a look at the irony-completion-candidates-async function to see you have this change:

This is the first change after the 1.1.0.

junkudo commented 6 years ago

I re-installed irony and company-irony from MELPA stable and am still running into the same issue. I also confirmed that I do not have that change you indicated.

rempfler commented 6 years ago

I am facing exactly the same issue as @junkudo on one of my machines (with Ubuntu 14.04). Did you find a solution?

EDIT: I solved the problem by upgrading emacs from version 24.3.1 to 25.3.2.