Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block for a long time on completion #12

Open
blahgeek opened this issue Dec 17, 2023 · 4 comments · May be fixed by emacs-lsp/lsp-mode#4262
Open

Block for a long time on completion #12

blahgeek opened this issue Dec 17, 2023 · 4 comments · May be fixed by emacs-lsp/lsp-mode#4262

Comments

@blahgeek
Copy link

Hello,

I compiled this json-rpc branch and tried it with lsp-mode (commit cb2b565b4e9b38be1f4c284e7618160383ad665d), but I found that emacs would randomly block for a long time on completion. Specifically, sometimes when I type "xxx.", the dot "." would not appear and emacs would block for about 10 seconds, then after that the dot and the completion popup would show.

I'm using the typescript language server (ts-ls).

This is the stacktrace when I press "C-g" during the blocking period:

Debugger entered--Lisp error: (quit)
  lsp-request("completionItem/resolve" #<hash-table equal 5/7 0x1576874ab2cd>)
  lsp-completion--resolve(#<hash-table equal 6/7 0x1576869e3dd5>)
  lsp-completion--exit-fn(#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))) finished #f(compiled-function () #<bytecode -0x15d2b6bbba872045>))
  apply(lsp-completion--exit-fn (#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))) finished #f(compiled-function () #<bytecode -0x15d2b6bbba872045>)))
  #f(compiled-function (&rest args-before) #<bytecode -0x8c5656343dcb1ae>)(#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))) finished)
  company--capf-post-completion(#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  #f(compiled-function (command &optional arg &rest args) "`company-mode' backend using `completion-at-point-functions'." (interactive #f(compiled-function () #<bytecode 0x198000e483dd>)) #<bytecode 0x1350e8b5c4f7b6e3>)(post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  apply(#f(compiled-function (command &optional arg &rest args) "`company-mode' backend using `completion-at-point-functions'." (interactive #f(compiled-function () #<bytecode 0x198000e483dd>)) #<bytecode 0x1350e8b5c4f7b6e3>) (post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)))))
  (let ((completion-styles '(basic partial-completion))) (apply capf-fn args))
  company-capf@my/set-completion-styles(#f(compiled-function (command &optional arg &rest args) "`company-mode' backend using `completion-at-point-functions'." (interactive #f(compiled-function () #<bytecode 0x198000e483dd>)) #<bytecode 0x1350e8b5c4f7b6e3>) post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  apply(company-capf@my/set-completion-styles #f(compiled-function (command &optional arg &rest args) "`company-mode' backend using `completion-at-point-functions'." (interactive #f(compiled-function () #<bytecode 0x198000e483dd>)) #<bytecode 0x1350e8b5c4f7b6e3>) (post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)))))
  company-capf(post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  apply(company-capf (post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)))))
  company-call-backend-raw(post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  company--force-sync(company-call-backend-raw (post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)))) company-capf)
  company-call-backend(post-completion #("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  company-cancel(#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  company-finish(#("diffBase" 0 1 (face (completions-first-difference) lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5)) 1 8 (lsp-completion-item #<hash-table equal 6/7 0x1576869e3dd5> lsp-sort-text "11" lsp-completion-start-point 3280 lsp-completion-markers (3280 #<marker (moves after insertion) at 3288 in App.tsx>) lsp-completion-prefix "diff" match-data (0 5 0 1 1 2 2 3 3 4 4 5))))
  company-complete-selection()
  funcall-interactively(company-complete-selection)
  command-execute(company-complete-selection)

@egstatsml
Copy link

I got a similar error as well. Am using this fork with it rebased on the 29.1 release commit.
Am using Corfu for completion. Here is the profiler report stopped right after the 10 second or so hang,

        7932  83% - corfu--post-command
        7932  83%  - corfu--exhibit
        7932  83%   - apply
        7932  83%    - #<compiled 0xcbaf26291267ea0>
        7932  83%     - apply
        7932  83%      - #<compiled 0x13e3c142bab4e7fe>
        7900  82%       - corfu--update
        7806  81%        - corfu--recompute
        7806  81%         - corfu--filter-completions
        7806  81%          - completion-all-completions
        7806  81%           - apply
        7806  81%            - #<subr completion-all-completions>
        7806  81%             - completion--nth-completion
        7806  81%              - completion--some
        7806  81%               - #<compiled -0x187b3ed5247e0bbf>
        7806  81%                - orderless-all-completions
        7806  81%                 - orderless-filter
        7806  81%                  - #<compiled 0x1103d45a62e426d>
        7803  81%                   - #<compiled -0x15d2ae1b76634325>
        7796  81%                    - lsp-request-while-no-input
        7792  81%                     - sit-for
        7658  80%                      - timer-event-handler
        7658  80%                       - apply
        7651  80%                        - corfu-popupinfo--show
        7651  80%                         - corfu-popupinfo--get-documentation
        7651  80%                          - #<compiled 0x54e189f93bc79b1>
        7648  80%                           - apply
        7648  80%                            - lsp-completion--get-documentation
        7644  80%                             - lsp-completion--resolve
        5445  57%                                lsp-request
           4   0%                             - lsp--render-element
           4   0%                              - lsp--render-string
           4   0%                               - lsp--fontlock-with-mode
           4   0%                                - lsp--render-markdown
           4   0%                                 - gfm-view-mode
           4   0%                                  + gfm-mode
           3   0%                           + lsp-doc-buffer
           5   0%                        + jinx--timer-handler
           2   0%                          #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_12>
          39   0%                      + redisplay_internal (C function)
           7   0%                    + lsp-completion--filter-candidates
           3   0%                     complete-with-action
          94   0%        + redisplay
          12   0%       + posn-at-point
           6   0%       + corfu--candidates-popup
         835   8% + ...
         437   4% + command-execute
         169   1% + timer-event-handler
         134   1% + redisplay_internal (C function)
          22   0% + evil-escape-pre-command-hook
           4   0% + jit-lock--antiblink-post-command
           3   0%   evil-repeat-pre-hook

And my relevent configs

(use-package lsp-mode
  :straight (lsp-mode
	     :type git
	     :host github
	     :repo "emacs-lsp/lsp-mode"
	     :pin "266945b3e470212305812581d24a938a96c47a3a")
  :init
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-c l")
  (setq lsp-completion-provider :none) ;; we use Corfu!
  ;; config fn to be run as hook taken from corfu wiki
  (defun my/lsp-mode-setup-completion ()
    (setf (alist-get 'styles (alist-get 'lsp-capf
					completion-category-defaults))
	  '(orderless))) ;; Configure orderless
  :commands (lsp lsp-deferred)
  :hook (lsp-mode . lsp-enable-which-key-integration)
  :hook (lsp-completion-mode . my/lsp-mode-setup-completion)
  :config
  (setq lsp-headerline-breadcrumb-enable nil)
  ;; increase read process max
  ;; as suggested in LSP performance docs
  ;; https://emacs-lsp.github.io/lsp-mode/page/performance/
  (setq read-process-output-max (* 1024 1024)) ;; 1mb
  ;; making lsp work in org-babel
  ;; taken from https://tecosaur.github.io/emacs-config/config.html#lsp-support-src
  (cl-defmacro lsp-org-babel-enable (lang)
    "Support LANG in org source code block."
    (cl-check-type lang stringp)
    (let* ((edit-pre (intern (format "org-babel-edit-prep:%s" lang)))
           (intern-pre (intern (format "lsp--%s" (symbol-name edit-pre)))))
      `(progn
	 (defun ,intern-pre (info)
           (let ((file-name (->> info caddr (alist-get :file))))
             (unless file-name
               (setq file-name (make-temp-file "babel-lsp-")))
             (setq buffer-file-name file-name)
             (lsp-deferred)))
	 (put ',intern-pre 'function-documentation
              (format "Enable lsp-mode in the buffer of org source block (%s)."
                      (upcase ,lang)))
	 (if (fboundp ',edit-pre)
             (advice-add ',edit-pre :after ',intern-pre)
           (progn
             (defun ,edit-pre (info)
               (,intern-pre info))
             (put ',edit-pre 'function-documentation
                  (format "Prepare local buffer environment for org source block (%s)."
                          (upcase ,lang))))))))
  (defvar org-babel-lang-list
    '("go" "python" "ipython" "bash" "sh"))
  (dolist (lang org-babel-lang-list)
    (eval `(lsp-org-babel-enable ,lang))))


(use-package lsp-pyright
  :straight t
  :hook (python-mode . (lambda ()
                         (require 'lsp-pyright)
                         (lsp-deferred))))  


(use-package corfu
  :straight t
  :init
  ;; these must be set before loading corfu
  ;; alot of these were stolen from the proposed doom module
  (setq corfu-auto t
        corfu-auto-delay 0.15
        corfu-auto-prefix 2
        corfu-excluded-modes '(erc-mode
                               circe-mode
                               help-mode
                               gud-mode
                               vterm-mode))
  ;; then enable corfu globally since I will use it a bunch
  (global-corfu-mode)
  :config
  (setq corfu-cycle t
        corfu-separator ?\s
	corfu-preselect t
	corfu-count 16
	corfu-max-width 120
	corfu-preview-current 'insert
	corfu-on-exact-match nil
	corfu-quit-at-boundary  'separator
	corfu-quit-no-match  'separator)

  ;; taken from doom
  ;; making sure when I push enter will actually insert current selection
  (with-eval-after-load 'evil-collection-corfu
    (evil-collection-define-key 'insert 'corfu-map
      (kbd "RET") #'corfu-insert
      [return] #'corfu-insert)))

@blahgeek
Copy link
Author

@egstatsml Hi can you try the mentioned PR? emacs-lsp/lsp-mode#4262

@egstatsml
Copy link

Yep I will give it a go, might need a day or two though (It shouldn't take long just busy for the next day at least).
If you don't hear from me in a couple days feel free to remind me.

@egstatsml
Copy link

Sorry for the super late response, definitely took me more than couple days just because of life.

It looks like this fix is working for me, but I saw your emacs-lsp-booster package, and that seems like a better fix for now. Thanks for your work on this PR and the booster package as well, I and I'm sure many others greatly appreciate it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants