最新的python lsp-mode的配置问题

升级到最新的lsp(包括升级了pyls)后,虽然看到部分lsp功能生效,但是还是有很多问题。 配置如下,我的理解这已经是最简配置了

(require 'lsp-mode)
(add-hook 'python-mode-hook #'lsp)

首先是lsp-describe-session出来capability如下,这正常吗?completionprovider下面有nil

[-] Capabilities
       |-[X] experimental:
       |-[X] textDocumentSync: 2
       |-[-] signatureHelpProvider:
       |  `-[X] triggerCharacters: (( , =)
       |-[X] renameProvider: t
       |-[X] referencesProvider: t
       |-[X] hoverProvider: t
       |-[-] executeCommandProvider:
       |  `-[X] commands: nil
       |-[X] definitionProvider: t
       |-[X] documentSymbolProvider: t
       |-[X] documentRangeFormattingProvider: t
       |-[X] documentHighlightProvider: t
       |-[X] documentFormattingProvider: t
       |-[-] completionProvider:
       |  |-[X] triggerCharacters: (.)
       |  `-[X] resolveProvider: nil
       |-[-] codeLensProvider:
       |  `-[X] resolveProvider: nil
       `-[X] codeActionProvider: t

另外,在py文件打字暂停后,company报错(可我在.emacs中并没有自动打开company,是lsp-mode启动的吗?)

Debugger entered--Lisp error: (void-function lsp--client-completion-in-comments\?)
  (lsp--client-completion-in-comments\? (progn (or (and (memq (type-of it) cl-struct-lsp--workspace-tags) t) (signal (quote wrong-type-argument) (list (quote lsp--workspace) it))) (aref it 6)))
  (setq needle (lsp--client-completion-in-comments\? (progn (or (and (memq (type-of it) cl-struct-lsp--workspace-tags) t) (signal (quote wrong-type-argument) (list (quote lsp--workspace) it))) (aref it 6))))
  (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? (progn (or (and (memq (type-of it) cl-struct-lsp--workspace-tags) t) (signal (quote wrong-type-argument) (list (quote lsp--workspace) it))) (aref it 6)))))
  (let ((it (car list))) (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal (quote wrong-type-argument) (list ... it))) (aref it 6))))))
  (while (and list continue) (let ((it (car list))) (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? (progn (or (and ... t) (signal ... ...)) (aref it 6)))))) (setq it-index (1+ it-index)) (setq list (cdr list)))
  (let ((list (lsp-workspaces)) (continue t) (it-index 0)) (while (and list continue) (let ((it (car list))) (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? (progn (or ... ...) (aref it 6)))))) (setq it-index (1+ it-index)) (setq list (cdr list))))
  (let (needle) (let ((list (lsp-workspaces)) (continue t) (it-index 0)) (while (and list continue) (let ((it (car list))) (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? (progn ... ...))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) needle)
  (or (let (needle) (let ((list (lsp-workspaces)) (continue t) (it-index 0)) (while (and list continue) (let ((it (car list))) (if (not (not needle)) (setq continue nil) (setq needle (lsp--client-completion-in-comments\? ...)))) (setq it-index (1+ it-index)) (setq list (cdr list)))) needle) (not (company-in-string-or-comment)))
  (and (and (boundp (quote lsp-mode)) lsp-mode) (lsp--capability "completionProvider") (or (let (needle) (let ((list (lsp-workspaces)) (continue t) (it-index 0)) (while (and list continue) (let ((it ...)) (if (not ...) (setq continue nil) (setq needle ...))) (setq it-index (1+ it-index)) (setq list (cdr list)))) needle) (not (company-in-string-or-comment))) (or (company-lsp--completion-prefix) (quote stop)))
  (cond ((eql command (quote interactive)) (company-begin-backend (function company-lsp))) ((eql command (quote prefix)) (and (and (boundp (quote lsp-mode)) lsp-mode) (lsp--capability "completionProvider") (or (let (needle) (let ((list ...) (continue t) (it-index 0)) (while (and list continue) (let ... ...) (setq it-index ...) (setq list ...))) needle) (not (company-in-string-or-comment))) (or (company-lsp--completion-prefix) (quote stop)))) ((eql command (quote candidates)) (or (company-lsp--cache-item-candidates (company-lsp--cache-get arg)) (and company-lsp-async (cons :async (function (lambda (callback) (company-lsp--candidates-async arg callback))))) (company-lsp--candidates-sync arg))) ((eql command (quote sorted)) t) ((eql command (quote no-cache)) (not (eq company-lsp-cache-candidates t))) ((eql command (quote annotation)) (lsp--annotate arg)) ((eql command (quote quickhelp-string)) (company-lsp--documentation arg)) ((eql command (quote doc-buffer)) (company-doc-buffer (company-lsp--documentation arg))) ((eql command (quote match)) (cdr (company-lsp--compute-flex-match arg))) ((eql command (quote post-completion)) (company-lsp--post-completion arg)))
  company-lsp(prefix)
  apply(company-lsp prefix)
  (if (functionp company-backend) (apply company-backend args) (apply (function company--multi-backend-adapter) company-backend args))
  (condition-case err (if (functionp company-backend) (apply company-backend args) (apply (function company--multi-backend-adapter) company-backend args)) ((debug user-error) (user-error "Company: backend %s user-error: %s" company-backend (error-message-string err))) ((debug error) (error "Company: backend %s error \"%s\" with args %s" company-backend (error-message-string err) args)))
  company-call-backend-raw(prefix)
  apply(company-call-backend-raw prefix)
  (let ((value (apply fun args))) (if (not (eq (car-safe value) :async)) value (let ((res (quote trash)) (start (time-to-seconds))) (funcall (cdr value) (function (lambda (result) (setq res result)))) (while (eq res (quote trash)) (if (> (- (time-to-seconds) start) company-async-timeout) (error "Company: backend %s async timeout with args %s" backend args) (sleep-for company-async-wait))) res)))
  company--force-sync(company-call-backend-raw (prefix) company-lsp)
  company-call-backend(prefix)
  (let ((company-backend backend)) (company-call-backend (quote prefix)))
  (progn (let ((company-backend backend)) (company-call-backend (quote prefix))))
  (if (company--maybe-init-backend backend) (progn (let ((company-backend backend)) (company-call-backend (quote prefix)))))
  (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn (let ((company-backend backend)) (company-call-backend (quote prefix))))) (company--multi-backend-adapter backend (quote prefix)))
  (setq prefix (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn (let ((company-backend backend)) (company-call-backend (quote prefix))))) (company--multi-backend-adapter backend (quote prefix))))
  (let ((backend (car --dolist-tail--))) (setq prefix (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn (let ((company-backend backend)) (company-call-backend (quote prefix))))) (company--multi-backend-adapter backend (quote prefix)))) (if prefix (progn (if (company--good-prefix-p prefix) (progn (let ((ignore-case ...)) (setq company-prefix (company--prefix-str prefix) company-backend backend c (company-calculate-candidates company-prefix ignore-case)) (cond (... ...) (... ...) (t ... ... ... ...))))) (throw (quote --cl-block-nil--) c))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((backend (car --dolist-tail--))) (setq prefix (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn (let (...) (company-call-backend ...)))) (company--multi-backend-adapter backend (quote prefix)))) (if prefix (progn (if (company--good-prefix-p prefix) (progn (let (...) (setq company-prefix ... company-backend backend c ...) (cond ... ... ...)))) (throw (quote --cl-block-nil--) c))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- (if company-backend (list company-backend) company-backends))) (while --dolist-tail-- (let ((backend (car --dolist-tail--))) (setq prefix (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn (let ... ...))) (company--multi-backend-adapter backend (quote prefix)))) (if prefix (progn (if (company--good-prefix-p prefix) (progn (let ... ... ...))) (throw (quote --cl-block-nil--) c))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  (catch (quote --cl-block-nil--) (let ((--dolist-tail-- (if company-backend (list company-backend) company-backends))) (while --dolist-tail-- (let ((backend (car --dolist-tail--))) (setq prefix (if (or (symbolp backend) (functionp backend)) (if (company--maybe-init-backend backend) (progn ...)) (company--multi-backend-adapter backend (quote prefix)))) (if prefix (progn (if (company--good-prefix-p prefix) (progn ...)) (throw (quote --cl-block-nil--) c))) (setq --dolist-tail-- (cdr --dolist-tail--))))))
  (let (prefix c) (catch (quote --cl-block-nil--) (let ((--dolist-tail-- (if company-backend (list company-backend) company-backends))) (while --dolist-tail-- (let ((backend (car --dolist-tail--))) (setq prefix (if (or ... ...) (if ... ...) (company--multi-backend-adapter backend ...))) (if prefix (progn (if ... ...) (throw ... c))) (setq --dolist-tail-- (cdr --dolist-tail--)))))))
  company--begin-new()
  (and (company--should-complete) (company--begin-new))
  (or (and company-candidates (company--continue)) (and (company--should-complete) (company--begin-new)))
  company--perform()
  (let ((inhibit-quit nil)) (company--perform) company-candidates)
  (condition-case err (let ((inhibit-quit nil)) (company--perform) company-candidates) ((debug error) (message "Company: An error occurred in auto-begin") (message "%s" (error-message-string err)) (company-cancel)) ((debug quit) (company-cancel)))
  (let ((company-idle-delay (quote now))) (condition-case err (let ((inhibit-quit nil)) (company--perform) company-candidates) ((debug error) (message "Company: An error occurred in auto-begin") (message "%s" (error-message-string err)) (company-cancel)) ((debug quit) (company-cancel))))
  (and company-mode (not company-candidates) (let ((company-idle-delay (quote now))) (condition-case err (let ((inhibit-quit nil)) (company--perform) company-candidates) ((debug error) (message "Company: An error occurred in auto-begin") (message "%s" (error-message-string err)) (company-cancel)) ((debug quit) (company-cancel)))))
  company-auto-begin()
  (if (company-auto-begin) (progn (company-input-noop) (let ((this-command (quote company-idle-begin))) (company-post-command))))
  (and (eq buf (current-buffer)) (eq win (selected-window)) (eq tick (buffer-chars-modified-tick)) (eq pos (point)) (if (company-auto-begin) (progn (company-input-noop) (let ((this-command (quote company-idle-begin))) (company-post-command)))))
  company-idle-begin(#<buffer __init__.py> #<window 3 on __init__.py> 30 324)
  apply(company-idle-begin (#<buffer __init__.py> #<window 3 on __init__.py> 30 324))
  timer-event-handler([t 23864 27603 947690 nil company-idle-begin (#<buffer __init__.py> #<window 3 on __init__.py> 30 324) nil 553000])

find ~/.emacs.d/ -name "*.elc" | xargs rm will probably solve your issue.

1赞

i already tried this, but it doesn’t work. even if i remove company-lsp then re-install it, i got the same error. the error goes away if i delete company-lsp. but now company-lsp is not in company-backend, so i still cannot auto-complete with company & lsp

Can you try to remove whole .emacs.d and redownload it? Also, make sure that you are using melpa for lsp-mode(not melpa stable).

removing some related packages and re-install solved the problem. Thanks! BTW, it seems i need to start emacs as sudo to be able to parse the packages installed under dist-package, for example requests. what might be the reason? i already gave read permission for everyone

ls -l /usr/lib/python3/dist-packages/requests/
total 204
-rwxr-xr-x 1 root root 20836 Aug  2  2017 adapters.py
-rwxr-xr-x 1 root root  6237 Jun 15  2017 api.py

I have no clue. You may ask in the language server repo with the concrete exception/error log.