shuxiao9058 / tabnine

An unofficial TabNine package for Emacs with TabNine Chat Supported
MIT License
33 stars 6 forks source link
capf chat company-mode emacs tabnine

+title: TabNine

[[https://melpa.org/#/tabnine][file:https://melpa.org/packages/tabnine-badge.svg]] [[https://github.com/shuxiao9058/tabnine/actions/workflows/melpazoid.yml][https://github.com/shuxiao9058/tabnine/actions/workflows/melpazoid.yml/badge.svg]]

An unofficial TabNine (with TabNine Chat supported) package for Emacs.

@@html:details>@@@@html:<summary@@ TabNine Complete @@html:@@ [[file:./assets/screenshot-3.gif]] @@html:@@

@@html:details>@@@@html:<summary@@ TabNine Chat @@html:@@ [[file:./assets/screenshot-4.gif]] @@html:@@

@@html:details>@@@@html:<summary@@ Snippets displayed with overlay @@html:@@ [[file:./assets/screenshot-1.png]] @@html:@@

@@html:details>@@@@html:<summary@@ Classic completions displayed with capf @@html:@@ [[file:./assets/screenshot-2.png]] @@html:@@

** disable overlay display

If you want to use =capf= only, disable =tabnine-mode= .

** Installation

*** Install TabNine package

TabNine is available on [[https://melpa.org/#/tabnine][Melpa]], you can install it with your favorite package manager.

@@html:details>@@@@html:<summary@@ Example for manual install @@html:@@

Clone or download this repository and add to your load path:

+begin_src elisp

(add-to-list 'load-path "") (require 'tabnine)

+end_src

+begin_src elisp

(with-eval-after-load 'company ;; disable inline previews (delq 'company-preview-if-just-one-frontend company-frontends))

(with-eval-after-load 'tabnine ;; (kbd "TAB") is literal ctrl-I, (kbd ") is the actual tab key (define-key tabnine-completion-map (kbd "TAB") #'tabnine-accept-completion) (define-key tabnine-completion-map (kbd "") #'tabnine-accept-completion)

(define-key tabnine-completion-map (kbd "M-f") #'tabnine-accept-completion-by-word) (define-key tabnine-completion-map (kbd "M-") #'tabnine-accept-completion-by-line)

(define-key tabnine-completion-map (kbd "C-g") #'tabnine-clear-overlay) (define-key tabnine-completion-map (kbd "M-[") #'tabnine-next-completion) (define-key tabnine-completion-map (kbd "M-]") #'tabnine-previous-completion))

(add-hook 'prog-mode-hook #'tabnine-mode) (add-hook 'kill-emacs-hook #'tabnine-kill-process)

+end_src

@@html:details>@@@@html:<summary@@ Example for use-package (straight) @@html:@@

+begin_src elisp

(use-package tabnine :commands (tabnine-start-process) :hook (prog-mode . tabnine-mode) :straight t :diminish "⌬" :custom (tabnine-wait 1) (tabnine-minimum-prefix-length 0) :hook (kill-emacs . tabnine-kill-process) :config (add-to-list 'completion-at-point-functions #'tabnine-completion-at-point) (tabnine-start-process) :bind (:map tabnine-completion-map ("" . tabnine-accept-completion) ("TAB" . tabnine-accept-completion) ("M-f" . tabnine-accept-completion-by-word) ("M-" . tabnine-accept-completion-by-line) ("C-g" . tabnine-clear-overlay) ("M-[" . tabnine-previous-completion) ("M-]" . tabnine-next-completion)))

+end_src

@@html:@@

@@html:details>@@@@html:<summary@@ Example for Doom Emacs @@html:@@

+begin_src elisp

(package! tabnine)

+end_src

+begin_src elisp

(use-package! tabnine :hook ((prog-mode . tabnine-mode) (kill-emacs . tabnine-kill-process)) :config (add-to-list 'completion-at-point-functions #'tabnine-completion-at-point) (tabnine-start-process) :bind (:map tabnine-completion-map ("" . tabnine-accept-completion) ("TAB" . tabnine-accept-completion) ("M-f" . tabnine-accept-completion-by-word) ("M-" . tabnine-accept-completion-by-line) ("C-g" . tabnine-clear-overlay) ("M-[" . tabnine-previous-completion) ("M-]" . tabnine-next-completion)))

+end_src

@@html:@@

@@html:details>@@@@html:<summary@@ Example for Spacemacs @@html:@@

Edit your ~/.spacemacs:

+begin_src elisp

;; =================== ;; dotspacemacs/layers ;; ===================

;; add or uncomment the auto-completion layer dotspacemacs-configuration-layers '( ... auto-completion ... )

;; add tabnine to additional packages dotspacemacs-additional-packages '((tabnine))

;; ======================== ;; dotspacemacs/user-config ;; ========================

;; accept completion from tabnine and fallback to company (with-eval-after-load 'company ;; disable inline previews (delq 'company-preview-if-just-one-frontend company-frontends))

(with-eval-after-load 'tabnine (define-key tabnine-completion-map (kbd "TAB") #'tabnine-accept-completion) (define-key tabnine-completion-map (kbd "") #'tabnine-accept-completion)

(define-key tabnine-completion-map (kbd "M-f") #'tabnine-accept-completion-by-word) (define-key tabnine-completion-map (kbd "M-") #'tabnine-accept-completion-by-line)

(define-key tabnine-completion-map (kbd "C-g") #'tabnine-clear-overlay) (define-key tabnine-completion-map (kbd "M-[") #'tabnine-next-completion) (define-key tabnine-completion-map (kbd "M-]") #'tabnine-previous-completion))

(add-hook 'prog-mode-hook 'tabnine-mode) (add-hook 'kill-emacs-hook #'tabnine-kill-process)

+end_src

@@html:@@

*** Install TabNine binary

After installing the TabNine package, you should finish the installation by executing the interactive command =tabnine-install-binary=.

** TabNine configuration

The advanced features (e.g. advanced completions, TabNine Chat) require a =TabNine Pro= account. Use =tabnine-login= command to login your TabNine account.

** TabNine Chat predefined prompts

| Command | Prompt | |-------------------------------------+-----------------------------------------------| | tabnine-chat-explain-code | Explain the selected code | | tabnine-chat-generate-test-for-code | Write tests for the selected code | | tabnine-chat-document-code | Add documentation for the selected code | | tabnine-chat-fix-code | Find errors in the selected code and fix them |

** tabnine-auto-balance

TabNine can automatically balance parentheses, by removing and adding closing parentheses after the cursor. See the examples [[https://github.com/zxqfl/TabNine/blob/master/HowToWriteAClient.md][here]].

** tabnine-mode-map

None.

** tabnine-completion-map

| Key | Action | |--------------+-----------------------------------| | TAB | tabnine-accept-completion | | C-g | tabnine-clear-overlay | | M-f | tabnine-accept-completion-by-word | | M- | tabnine-accept-completion-by-line | | M-[ | tabnine-previous-completion | | M-] | tabnine-next-completion |

** tabnine-chat-mode-map

| Key | Action | |---------+-------------------| | C-c RET | tabnine-chat-send |

** Heavy memory and CPU usage

** ICON displayed error

If candidate icons of tabnine are displayed wrongly [[https://github.com/shuxiao9058/tabnine/issues/1][capf icon error]], try to set =kind-icon-mapping= for tabnine:

+begin_src emacs-lisp

(add-to-list 'kind-icon-mapping '(tabnine "ai" :icon "cloud" :face shadow) t)

+end_src

+begin_src emacs-lisp

(add-to-list 'kind-icon-mapping `(tabnine ,(nerd-icons-codicon "nf-cod-hubot") :face font-lock-warning-face) t)

+end_src

Thanks to the great work of [[https://github.com/TommyX12][Tommy Xiang]], [[https://github.com/zerolfx/copilot.el][zerolfx]] and [[https://github.com/karthink][karthink]].

These projects helped me a lot:

https://github.com/TommyX12/company-tabnine

https://github.com/50ways2sayhard/tabnine-capf

https://github.com/zerolfx/copilot.el

https://github.com/karthink/gptel

Licensed under GPLv3.