Skip to content
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

ess company-tabnine backend #955

Closed
George9000 opened this issue Aug 2, 2019 · 7 comments
Closed

ess company-tabnine backend #955

George9000 opened this issue Aug 2, 2019 · 7 comments

Comments

@George9000
Copy link

company-tabnine is a completion backend for company mode. It provides completion based on a machine learning completer called TabNine

This backend works successfully in all modes except ess. Attempts to solve the problem included adding it as a company-backend to ess following the discussion in #565 or adding it to the list ess-r-company-backends. Completion is tested in the source buffer after starting an inferior R. However, the TabNIne backend completion is ignored in ESS. Switching to fundamental-mode immediately restores functionality.

Example of one configuration attempt:
(require 'company-tabnine)
(add-to-list 'company-backends #'company-tabnine)
;; Trigger completion immediately.
(setq company-idle-delay 0)

;; Number the candidates (use M-1, M-2 etc to select completions).
(setq company-show-numbers t)

;; Use the tab-and-go frontend.
;; Allows TAB to select and complete at the same time.
(company-tng-configure-default)
(setq company-frontends
'(company-tng-frontend
company-pseudo-tooltip-frontend
company-echo-metadata-frontend))

;; don't auto-insert ess backends
(setq ess-use-company nil)

(defun my-ess-config ()
(make-variable-buffer-local 'company-backends)
(add-to-list 'company-backends
'(company-tabnine company-R-args company-R-objects company-dabbrev-code :separate)))

(add-hook 'ess-mode-hook #'my-ess-config)

@jabranham
Copy link
Contributor

I'm surprised modifying ess-r-company-backends doesn't work. Did you try it this way:

(setq ess-r-company-backends
      '((company-tabnine company-R-library company-R-args company-R-objects :separate)))

As a disclaimer I'm not a company user myself :-)

@George9000
Copy link
Author

Thank you. That worked.

For others who may come here with the same issue, here are two approaches to the config in spacemacs (which would likely work very similarly in a plain .emacs init file)

In the user-config section of .spacemacs

(require 'company-tabnine)
(add-to-list 'company-backends #'company-tabnine)
(setq company-idle-delay 0)
(setq company-show-numbers t)
(company-tng-configure-default)
(setq company-frontends
      '(company-tng-frontend
        company-pseudo-tooltip-frontend
        company-echo-metadata-frontend))
(setq ess-r-company-backends
      '((company-tabnine company-R-library company-R-args company-R-objects :separate)))

Alternatively, in a private layer, mylayer, (~/.emacs.d/private/mylayer/packages.el):

(defun mylayer/init-company-tabnine ()
  (use-package company-tabnine
    :ensure t
    :init
    (progn
      (add-to-list 'spacemacs-default-company-backends #'company-tabnine)
      (company-tng-configure-default)
      (setq company-idle-delay 0
            company-show-numbers t
            company-frontends
            '(company-tng-frontend
              company-pseudo-tooltip-frontend
              company-echo-metadata-frontend)
            )
      )))

(setq ess-r-company-backends
      '((company-tabnine company-R-library company-R-args company-R-objects :separate)))

For users of doom emacs, first uncomment ess in ~/.doom.d/init.el, then in ~/.doom.d/config.el

(require 'company-tabnine)
(add-to-list 'company-backends #'company-tabnine)
(setq company-idle-delay 0)
(setq company-show-numbers t)
(company-tng-configure-default)
(setq company-frontends
      '(company-tng-frontend
        company-pseudo-tooltip-frontend
        company-echo-metadata-frontend))

(after! ess-r-mode
  (set-company-backend! 'ess-r-mode
    '(:separate company-tabnine company-R-library company-R-args company-R-objects)))

@jabranham
Copy link
Contributor

Thanks for letting us know! I'm reopening this because it's not clear to me why ess sets company-backends buffer locally the way it does.

@jabranham jabranham reopened this Aug 3, 2019
@nverno
Copy link
Contributor

nverno commented Aug 3, 2019

Setting them buffer locally is pretty standard. It's easier to manage effective backends per mode, since they tend to behave differently and ordering matters.

@vspinu
Copy link
Member

vspinu commented Aug 3, 2019

Indeed. The idea is to make company work out of the box by default. Those familiar with company can overwrite company-backends themselve, or, if so desired, ess-r-company-backends. In fact we can make the latter a defcustom for an even easier customization, but benefits are marginal.

@jabranham
Copy link
Contributor

Ah, OK. That all makes sense I guess. And if it's standard to treat it this way I suppose we can just close this issue then.

@danielchen26
Copy link

I was wondering how to setup the user-config for ess-julia together using company-tabnine.

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

5 participants