company-capf 又出错了

Company: backend company-capf error "ValueError: ‘line‘ parameter is not in a valid range." with args (candidates dic)

今天一早起来写 python 就发现这个错误,怪不得补全信息一直出错,在google上查了半天,没有查到相关帖子
这个到底是 company的问题还是lsp的问题?? 我的 lsp 配置最近从 Chen Bin 那抄的,稍微改动了一下,没改动之前也是这个错误,只不过报错的对象变成了 LSP

(with-eval-after-load 'lsp-mode
  ;; enable log only for debug
  (setq lsp-log-io nil)
  ;; use `evil-matchit' instead
  (setq lsp-enable-folding nil)
  ;; no real time syntax check
  ;; (setq lsp-diagnostic-package :none)
  ;; handle yasnippet by myself
  (setq lsp-enable-snippet nil)
  ;; use `company-ctags' only.
  ;; Please note `company-lsp' is automatically enabled if it's installed
  (setq lsp-enable-completion-at-point t)
  ;; turn off for better performance
  (setq lsp-enable-symbol-highlighting nil)
  ;; use find-fine-in-project instead
  (setq lsp-enable-links nil)
  ;; auto restart lsp
  (setq lsp-restart 'auto-restart)
  ;; don't watch 3rd party javascript libraries
  (push "[/\\\\][^/\\\\]*\\.\\(json\\|html\\|jade\\)$" lsp-file-watch-ignored)
  ;; don't ping LSP language server too frequently
  (defvar lsp-on-touch-time 0)
  (defun my-lsp-on-change-hack (orig-fun &rest args)
    ;; do NOT run `lsp-on-change' too frequently
    (when (> (- (float-time (current-time))
                lsp-on-touch-time) 120) ;; 2 mins
      (setq lsp-on-touch-time (float-time (current-time)))
      (apply orig-fun args)))
  (advice-add 'lsp-on-change :around #'my-lsp-on-change-hack))

(provide 'config-lsp)

另外,这是 company-mode的配置

;; -*- coding: utf-8; lexical-binding: t; -*-

(add-hook 'after-init-hook 'global-company-mode)

;; evil has already integrated company-mode, see evil-integration.el

(defvar my-company-zero-key-for-filter nil
  "If t, pressing 0 calls `company-filter-candidates' per company's status.")

(with-eval-after-load 'company

  (defun my-company-number ()
    "Forward to `company-complete-number'.
Unless the number is potentially part of the candidate.
In that case, insert the number."
    (interactive)
    (let* ((k (this-command-keys))
           (re (concat "^" company-prefix k))
           (n (if (equal k "0") 10 (string-to-number k))))
      (cond
       ((or (cl-find-if (lambda (s) (string-match re s)) company-candidates)
            (> n (length company-candidates))
            (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
        (self-insert-command 1))

       ((and (eq n 10) my-company-zero-key-for-filter)
        (company-filter-candidates))

       (t
        (company-complete-number n)))))

  ;; @see https://github.com/company-mode/company-mode/issues/348
  (company-statistics-mode)
  (push 'company-cmake company-backends)
  (push 'company-c-headers company-backends)
  ;; (push 'company-yasnippet company-backends)
  ;; (push 'company-capf company-backends)
  ;; can't work with TRAMP
  (setq company-backends (delete 'company-ropemacs company-backends))

  ;; @see https://oremacs.com/2017/12/27/company-numbers/
  ;; Using digits to select company-mode candidates
  (let ((map company-active-map))
    (mapc
     (lambda (x)
       (define-key map (format "%d" x) 'my-company-number))
     (number-sequence 0 9)))

  (setq company-auto-commit t)
  ;; characters "/ ) . , ;"to trigger auto commit
  (setq company-auto-commit-chars '(92  41 46 44 59))

  ;; company-ctags is much faster out of box. No further optimiation needed
  (unless (featurep 'company-ctags) (local-require 'company-ctags))
  (company-ctags-auto-setup)

  ;; (setq company-backends (delete 'company-capf company-backends))

  ;; I don't like the downcase word in company-dabbrev
  (setq company-dabbrev-downcase nil
        ;; make previous/next selection in the popup cycles
        company-selection-wrap-around t
        ;; Some languages use camel case naming convention,
        ;; so company should be case sensitive.
        company-dabbrev-ignore-case nil
        ;; press M-number to choose candidate
        company-show-numbers t
        company-idle-delay 0.2
        company-clang-insert-arguments nil
        company-require-match nil
        company-ctags-ignore-case t ; I use company-ctags instead
        ;; @see https://github.com/company-mode/company-mode/issues/146
        company-tooltip-align-annotations t)

  ;; Press SPACE will accept the highlighted candidate and insert a space
  ;; "M-x describe-variable company-auto-complete-chars" for details.
  ;; So that's BAD idea.
  (setq company-auto-complete nil)

  ;; NOT to load company-mode for certain major modes.
  ;; Ironic that I suggested this feature but I totally forgot it
  ;; until two years later.
  ;; https://github.com/company-mode/company-mode/issues/29
  (setq company-global-modes
        '(not
          eshell-mode
          comint-mode
          erc-mode
          gud-mode
          rcirc-mode
          minibuffer-inactive-mode)))

;; (with-eval-after-load 'company-ispell
;;   (defun my-company-ispell-available-hack (orig-func &rest args)
;;     ;; in case evil is disabled
;;     (my-ensure 'evil-nerd-commenter)
;;     (cond
;;      ((and (derived-mode-p 'prog-mode)
;;            (or (not (company-in-string-or-comment)) ; respect advice in `company-in-string-or-comment'
;;                ;; I renamed the api in new version of evil-nerd-commenter
;;                (not (if (fboundp 'evilnc-pure-comment-p) (evilnc-pure-comment-p (point))
;;                       (evilnc-is-pure-comment (point)))))) ; auto-complete in comment only
;;       ;; only use company-ispell in comment when coding
;;       nil)
;;      (t
;;       (apply orig-func args))))
;;   (advice-add 'company-ispell-available :around #'my-company-ispell-available-hack))

;; (defun my-add-ispell-to-company-backends ()
;;   "Add ispell to the last of `company-backends'."
;;   (setq company-backends
;;         (add-to-list 'company-backends 'company-ispell)))

;; ;; {{ setup company-ispell
;; (defun toggle-company-ispell ()
;;   "Toggle company-ispell."
;;   (interactive)
;;   (cond
;;    ((memq 'company-ispell company-backends)
;;     (setq company-backends (delete 'company-ispell company-backends))
;;     (message "company-ispell disabled"))
;;    (t
;;     (my-add-ispell-to-company-backends)
;;     (message "company-ispell enabled!"))))

;; (defun company-ispell-setup ()
;;   ;; @see https://github.com/company-mode/company-mode/issues/50
;;   (when (boundp 'company-backends)
;;     (make-local-variable 'company-backends)
;;     (my-add-ispell-to-company-backends)
;;     ;; @see https://github.com/redguardtoo/emacs.d/issues/473
;;     (cond
;;      ((and (boundp 'ispell-alternate-dictionary)
;;            ispell-alternate-dictionary)
;;       (setq company-ispell-dictionary ispell-alternate-dictionary))
;;      (t
;;        (setq company-ispell-dictionary (file-truename (concat my-emacs-d "misc/english-words.txt")))))))

;; message-mode use company-bbdb.
;; So we should NOT turn on company-ispell
;; (add-hook 'org-mode-hook 'company-ispell-setup)
;; }}

(provide 'config-company)

:mag_right: "ValueError: ‘line‘ parameter is not in a valid range." with args - Google Search