添加了company backend后发现无法通过输入字符筛选东西。
如下图所示:从输入.
开始到输入.upda
补全的candidates都是一样的。。。
配置的代码如下:
(use-package lsp-javascript-typescript
:commands (lsp-javascript-typescript-enable)
:init
(add-hook 'js-mode-hook #'lsp-javascript-typescript-enable)
(add-hook 'typescript-mode-hook #'lsp-javascript-typescript-enable) ;; for typescript support
(add-hook 'js2-mode-hook #'lsp-javascript-typescript-enable) ;; for js2-mode support
(add-hook 'rjsx-mode #'lsp-javascript-typescript-enable) ;; for rjsx-mode support
(spacemacs|add-company-backends
:backends company-lsp
:modes js2-mode)
:defer t)
这个macro的定义在这里spacemacs|add-company-backends。
得到的company-backends-js2-mode的value如下:
Its value is ((company-lsp :with company-yasnippet)
(company-tern :with company-yasnippet)
(company-dabbrev-code company-gtags company-etags company-keywords :with company-yasnippet)
(company-files :with company-yasnippet)
(company-dabbrev :with company-yasnippet))
也试过把company-tern删掉,但也没什么用。
求教如何fix。
看了下lsp-python启用的方法,是(add-hook 'python-mode-local-vars-hook #'spacemacs//python-setup-company)
,使用的hook是loca-vars-hook,我尝试着把add-company-backends
函数添加到js2-mode-hook
,然而效果还是一样的。
其他函数定义如下:
(defun spacemacs//python-setup-company ()
"Conditionally setup company based on backend."
(pcase python-backend
(`anaconda (spacemacs//python-setup-anaconda-company))
(`lsp (spacemacs//python-setup-lsp-company))))
(defun spacemacs//python-setup-lsp-company ()
"Setup lsp auto-completion."
(if (configuration-layer/layer-used-p 'lsp)
(progn
(spacemacs|add-company-backends
:backends company-lsp
:modes python-mode)
(company-mode))
(message "`lsp' layer is not installed, please add `lsp' layer to your dofile.")))
找到解决方案了。
;; https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379
(defun my-company-transformer (candidates)
(let ((completion-ignore-case t))
(all-completions (company-grab-symbol) candidates)))
(defun my-js-hook nil
(make-local-variable 'company-transformers)
(push 'my-company-transformer company-transformers))
(add-hook 'js2-mode-hook 'my-js-hook)
每天不是被问字体就是被问主题,楼主的审美很受认可啊。