请帮我看看这个函数有什么问题

我想写一个基于lsp mode的pythn layer。lsp-python要求安装python-language-server。所以我参照现有python layer对anaconda的处理方法写了一个安装那个server的函数。

问题是

我在use-package里用那个函数就会报错:

Error (use-package): lsp-python/:config: Wrong number of arguments: (1 . 1), 2

我没有在函数里声明参数,用的时候也没传参数,这个问题是怎么来的啊?

packages.el

最后一行的函数(ensure-lsp-python-server)

(defun lsp-python/init-lsp-python ()
  (use-package lsp-python
    :init (lsp-mode)
    :config
    (add-hook 'python-mode-hook #'flycheck-mode)
    (add-hook 'python-mode-hook #'lsp-python-enable)
    (when python-enable-format-on-save
      (add-hook 'python-mode-hook 'add-python-format-on-save))
    ;; other python settings
    (setq python-shell-interpreter default-python-interpreter)
    (ensure-lsp-python-server)))

funcs.el

(defcustom lsp-python-server-install-directory
  "~/.emacs.d/lsp-python-server"
  "Installation directory for lsp python server."
  :type 'directory)

(defun ensure-lsp-python-server ()
  (unless (file-directory-p lsp-python-server-install-directory)
    (install-lsp-python-server)))


(defun install-lsp-python-server ()
  (shell-command-to-string (concat "pip install python-language-server --target ") lsp-python-server-install-directory)
  (when python-enable-mypy
    (shell-command-to-string (concat "pip install pyls-mypy --target ") lsp-python-server-install-directory))
  (when python-enable-import-sort
    (shell-command-to-string (concat "pip install pyls-isort --target ") lsp-python-server-install-directory))
  (setenv "PATH"
          (concat
           lsp-python-server-install-directory ";"
           (getenv "PATH"))))

试试 M-x toggle-debug-on-error ,Backtrace 里面应该能够给出出错的地方。

这里 shell-command-to-string 只能接受一个参数,但你传了两个。后面两句有同样的问题。

1 个赞