推荐入坑TabNine

我用了TabNine 把lsp给关了 lsp不是依赖后端的么。。我怕有冲突

我记得tabnine官网说和lsp是兼容的。

现在tab9可以和其他后端配合使用了,tab9后端我放在最前面,其他后端后备顶上

(defun use-package-list-insert (elem xs &optional anchor after test)
  "Insert ELEM into the list XS.
If ANCHOR is also a keyword, place the new KEYWORD before that
one.
If AFTER is non-nil, insert KEYWORD either at the end of the
keywords list, or after the ANCHOR if one has been provided.
If TEST is non-nil, it is the test used to compare ELEM to list
elements. The default is `eq'.
The modified list is returned. The original list is not modified."
  (let (result)
    (dolist (k xs)
      (if (funcall (or test #'eq) k anchor)
          (if after
              (setq result (cons k result)
                    result (cons elem result))
            (setq result (cons elem result)
                  result (cons k result)))
        (setq result (cons k result))))
    (if anchor
        (nreverse result)
      (if after
          (nreverse (cons elem result))
        (cons elem (nreverse result))))))

(with-eval-after-load 'lsp-mode
  (require 'company-lsp)
  (setq company-backends
        (use-package-list-insert #'company-lsp company-backends
                                 'company-tabnine t)))

(with-eval-after-load 'company
  (push #'company-tabnine company-backends))
1 个赞

好的 我等会试试

你在加拿大读书?富人呀

可以通过 company-transformers 实现 TabNine 和 lsp 同时用

(defun company//sort-by-tabnine (candidates)
  (if (or (functionp company-backend)
          (not (and (listp company-backend) (memq 'company-tabnine company-backend))))
      candidates
    (let ((candidates-table (make-hash-table :test #'equal))
          candidates-1
          candidates-2)
      (dolist (candidate candidates)
        (if (eq (get-text-property 0 'company-backend candidate)
                'company-tabnine)
            (unless (gethash candidate candidates-table)
              (push candidate candidates-2))
          (push candidate candidates-1)
          (puthash candidate t candidates-table)))
      (setq candidates-1 (nreverse candidates-1))
      (setq candidates-2 (nreverse candidates-2))
      (nconc (seq-take candidates-1 2)
             (seq-take candidates-2 2)
             (seq-drop candidates-1 2)
             (seq-drop candidates-2 2)))))

(add-to-list 'company-transformers 'company//sort-by-tabnine t)
;; `:separate`  使得不同 backend 分开排序
(add-to-list 'company-backends '(company-lsp :with company-tabnine :separate))

以上代码效果就是, 前 2 个 candidates 是 company-lsp 的, 接着的 2 个是 TabNine 的.

14 个赞

有谁用过 https://github.com/tensorflow/tensorflow 吗?

用上了,挺不错

请问,这个方案有没能去重的思路呢?

是基于云的吗?会有安全/隐私风险吗?

:raising_hand_man: 大佬咋了?

稍微改了下代码, 应该可以去重

1 个赞

感谢,好用!

大佬! 赞👍! 用上后真香!

不错不错 很好很强大

tab9 和 html emmet 不能共存么

TabNine的免费版已经足够好用了,但是在超过400kb的项目中,它总是通过 company 来提示我升级付费版本。

今天写了一小段代码让 company 不要烦我:

;; The free version of TabNine is good enough,
;; and below code is recommended that TabNine not always
;; prompt me to purchase a paid version in a large project.
(defadvice company-echo-show (around disable-tabnine-upgrade-message activate)
  (let ((company-message-func (ad-get-arg 0)))
    (when (and company-message-func
               (stringp (funcall company-message-func)))
      (unless (string-match "The free version of TabNine only indexes up to" (funcall company-message-func))
        ad-do-it))))

加上上面代码, TabNine 就专心的干活,不会一直在那里烦人了。

16 个赞

太坏了 :+1:

为啥我还是不停的报错?

Restarting TabNine process.
TabNine server started.
TabNine process #<process company-tabnine--process> received event "killed: 9".
TabNine process restart limit reached.

为啥我无法选择补全选项,只能起提示作用,不能选择吗?