company-lsp

因为下半年估计要写python、lua、js,不太想每个用一个 IDE。

先配置了 lsp server 的 python server,然后也设置了 company-backends,开启了 lsp 以及 lsp-python-enable。

但是补全是提示:

Company: An error occurred in auto-begin
Company: backend company-lsp error "Wrong type argument: arrayp, nil" with args (prefix)

有哪位大神知道原因嘛?

你得把你的配置贴出来吧

M-x toggle-debug-on-error 触发出错,看调用栈是怎样的

调用栈:

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  company-lsp(prefix)
  apply(company-lsp prefix)
  company-call-backend-raw(prefix)
  apply(company-call-backend-raw prefix)
  company--force-sync(company-call-backend-raw (prefix) company-lsp)
  company-call-backend(prefix)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer DefaultTest.py> #<window 3 on DefaultTest.py> 436 1213)
  apply(company-idle-begin (#<buffer DefaultTest.py> #<window 3 on DefaultTest.py> 436 1213))
  timer-event-handler([t 23402 19177 934503 nil company-idle-begin (#<buffer DefaultTest.py> #<window 3 on DefaultTest.py> 436 1213) nil 0])

配置用的 spacemacs 的 lsp-python,layer配置:

   dotspacemacs-configuration-layers
   '(
     git
     ivy
     (python :variables
             python-backend 'lsp))

我的 python 的 layer 配置:

(defconst my-python-packages
  '(
    exec-path-from-shell
    python
    )
  )

(defun my-python/init-exec-path-from-shell ()
  (use-package exec-path-from-shell
    :init
    (exec-path-from-shell-initialize)))

(defun my-python/post-init-python ()
  (add-hook 'python-mode-hook
            '(lambda ()
               ;; Use `ignore-errors' avoid LSP failed.
               (ignore-errors (lsp-python-enable()))
               )))

应该是 pyls 没有搞好,弄不清什么情况。

重新安装了一遍 python-language-server,这次不是用 root 安装的,貌似不报那个错误了。

现在错误是:

File mode specification error: (error Couldn’t find executable pyls)

设置一下ENV

有lsp layer,然后lsp-python-enable不需要后面加()

现在有个eglot,用着挺方便,可以试试

按楼上去掉 () 可以用了,试了下 python,还是挺好用的,不过与 pycharm 相比还是不那么省心。 滚回去用 pycharm 、webstorm写代码了,因为一直用 idea,装个插件也可以写lua。

emacs当平时的便捷工具和备忘记录了。有时间时候也用来折腾折腾。