2

Autocompletion doesn't work with tide or Tern, I have to M-x company-complete-common. I would like for it to keep suggesting with a dropdown menu as I type, but I can't manage to. It works just fine with elpy and go-mode.
I am using emacs 25.3.1 and I have these init lines regarding to js2-mode with tern:

(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; Better imenu
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
(require 'js2-refactor)
(require 'xref-js2)

(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-r")
(define-key js2-mode-map (kbd "C-k") #'js2r-kill)

;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
;; unbind it.
(define-key js-mode-map (kbd "M-.") nil)

(add-hook 'js2-mode-hook (lambda ()
 (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))

(require 'company)
(require 'company-tern)

(add-to-list 'company-backends 'company-tern)
(add-hook 'js2-mode-hook (lambda ()
                           (tern-mode)
                           (company-mode)))

;; Disable completion keybindings, as we use xref-js2 instead
(define-key tern-mode-keymap (kbd "M-.") nil)
(define-key tern-mode-keymap (kbd "M-,") nil)

regarding tide:

;; tide
(defun setup-tide-mode ()
 (interactive)
 (tide-setup)
 (flycheck-mode +1)
 (setq flycheck-check-syntax-automatically '(save mode-enabled))
 (eldoc-mode +1)
 (company-mode +1))

;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)

;; formats the buffer before saving
(add-hook 'before-save-hook 'tide-format-before-save)

(add-hook 'typescript-mode-hook #'setup-tide-mode)

There is no error on init, and company-mode is enabled on these modes as expected, it just doesn't start suggesting as typing goes, instead only works for manual completion.

Pedro Queiroga
  • 131
  • 1
  • 4
  • Do you have `company-mode` installed? –  Nov 25 '17 at 13:53
  • Did you install tern and added a `.tern-config` or `.tern-project` file? – caisah Nov 25 '17 at 16:38
  • @DoMiNeLa10 yes, and it works if I initiate completion manually, it shows a list of suggestion or if only one is possible it completes. It also works with other major modes such as go-mode and elpy. – Pedro Queiroga Nov 25 '17 at 17:23
  • @caisah I have tern installed tern and I do have a `.tern-project` file, nothing changes if I have this file or not, though. Same goes for a `.tern-config` file. – Pedro Queiroga Nov 25 '17 at 17:29
  • 1
    for tide, change " (add-hook 'typescript-mode-hook #'setup-tide-mode)" to " (add-hook 'js2-mode-hook #'setup-tide-mode)" and put a "jsconfig.json" file in your project path(https://code.visualstudio.com/docs/languages/jsconfig). – Pedro Nov 26 '17 at 00:41
  • @Pedro yes, sorry, I forgot to say that for javascript I am using tern and tide only for typescript and tsx. They both showed the same problem so I grouped them. I posted an anwser: `(setq company-idle-delay 0)` did what I wanted. – Pedro Queiroga Nov 26 '17 at 20:36
  • for tern, I think maybe is a 'company-backends' problem in your Emacs config. I've use a vanilla config with tern, js2, js2-refactor and xref-js2, and it works with default '0.5' value to company-idle-delay. tested it in GNU Emacs 25.1.1 (OSX) and the emacs configuration file, https://pastebin.com/bhZdsmbN – Pedro Nov 26 '17 at 22:23
  • I see. What I have discovered so far, experimenting, is that with go-mode, company-idle-delay is nil and completion works fine. With elpy, company-idle-delay is automatically 0.01, but if I change it to nil it still works. With tide and tern I have to have it different than nil for it to work. – Pedro Queiroga Nov 26 '17 at 23:40

2 Answers2

0

I asked around and what solved it for me was setting company-idle-delay to 0!
Previously it was nil, since it still worked on other modes I believe they don't follow a standard in processing this variable. I will add this to my init.el.

edit: I went through my init file with a fine comb and I found why company-idle-delay was set to nil, it was a line that I put there a year or so ago.

Pedro Queiroga
  • 131
  • 1
  • 4
0

You should try with

(setq company-minimum-prefix-length 1)

Its default value is 3, so you have to type 3 chars before autocompletion pop-up appears.