emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.76k stars 875 forks source link

Company mode with lsp-mode stops working #1853

Closed benwainwright closed 4 years ago

benwainwright commented 4 years ago

Before logging the bug, please make sure that:

  1. You are using the latest version of lsp-mode related packages. ✅
  2. You may also try reproduce the issue using clean environment using the following command ✅ (see below)
  3. Check FAQ and Troubleshooting section (https://github.com/emacs-lsp/lsp-mode#faq and https://github.com/emacs-lsp/lsp-mode#troubleshooting) ❌ The problem is related to the way that company interacts with lsp-mode, and isn't covered there.

Describe the bug I use company-mode in conjunction with lsp-mode and it seems that when I'm using it, after a period of time, it just... stops working. lsp-mode appears to be still active and working, but the company autosuggestion box seems to just stop appearing. At the present time I only seem to be able to resolve it by restarting emacs. Any suggestions on what I can do to debug this would be much appreciated.

I've already raised an issue with company-mode (https://github.com/company-mode/company-mode/issues/991) and they've advised me to post here

To Reproduce I've managed to reproduce by taking lsp-start-plain.el and adding company to the package list and the specific parts of my config that relate to company and lsp (also evil because I can't really use raw emacs, so its hard to test without it):

(defvar company-lsp-cache-candidates)
(setq company-lsp-cache-candidates t)

(setq company-backends (remove 'company-gtags company-backends))
(setq company-backends (remove 'company-etags company-backends))
(setq company-minimum-prefix-length 0)
(setq company-dabbrev-downcase 0)

(setq company-idle-delay 0)
(setq lsp-prefer-capf t)
(setq read-process-output-max (* 1024 1024))
(setq gc-cons-threshold 100000000)
(add-hook 'after-init-hook 'global-company-mode)

(setenv "TSSERVER_LOG_FILE" "/tmp/tsserver.log")
(add-hook 'typescript-mode-hook #'lsp)

(evil-mode 1)

Expected behavior Autosuggestions continue to appear until the end of time

Which Language Server did you use ts-ls

OS MacOS 10.14.6

kiennq commented 4 years ago

Can you follow https://emacs-lsp.github.io/lsp-mode/page/troubleshooting/ and gather *lsp-log* and workspace log (lsp-toggle-trace-io and lsp-workspace-show-log) after you can repro your issue?

benwainwright commented 4 years ago

Also, I noticed that I appear to suddenly be getting an error with the following stack trace. After I q out of the stack trace company-mode is no longer working:

Debugger entered--Lisp error: (cl-assertion-failed ((and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) "[yas] `yas-expand-snippet' needs properly setup `y..."))
  cl--assertion-failed((and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) "[yas] `yas-expand-snippet' needs properly setup `y..." nil nil)
  (or (and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) (cl--assertion-failed '(and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) "[yas] `yas-expand-snippet' needs properly setup `y..." (list) (list)))
  (progn (or (and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) (cl--assertion-failed '(and yas-minor-mode (memq 'yas--post-command-handler post-command-hook)) "[yas] `yas-expand-snippet' needs properly setup `y..." (list) (list))) nil)
  yas-expand-snippet(#("addEnvironment" 0 14 (fontified nil)) 821 835)
  (let (yas-indent-line) (yas-expand-snippet (lsp--to-yasnippet-snippet (buffer-substring start-point (point))) start-point (point)))
  (progn (let (yas-indent-line) (yas-expand-snippet (lsp--to-yasnippet-snippet (buffer-substring start-point (point))) start-point (point))))
  (if (eq insert-text-format\? 2) (progn (let (yas-indent-line) (yas-expand-snippet (lsp--to-yasnippet-snippet (buffer-substring start-point (point))) start-point (point)))))
  (let* ((--dash-source-106-- (text-properties-at 0 candidate)) (item (plist-get --dash-source-106-- 'lsp-completion-item)) (start-point (plist-get --dash-source-106-- 'lsp-completion-start-point)) (markers (plist-get --dash-source-106-- 'lsp-completion-markers)) (prefix (plist-get --dash-source-106-- 'lsp-completion-prefix)) (label (gethash "label" item)) (insert-text\? (gethash "insertText" item)) (text-edit\? (gethash "textEdit" item)) (insert-text-format\? (gethash "insertTextFormat" item)) (additional-text-edits\? (gethash "additionalTextEdits" item))) (cond (text-edit\? (apply #'delete-region markers) (insert prefix) (lsp--apply-text-edit text-edit\?)) ((or insert-text\? label) (apply #'delete-region markers) (insert prefix) (delete-region start-point (point)) (insert (or insert-text\? label)))) (if (eq insert-text-format\? 2) (progn (let (yas-indent-line) (yas-expand-snippet (lsp--to-yasnippet-snippet (buffer-substring start-point (point))) start-point (point))))) (if (and lsp-completion-enable-additional-text-edit additional-text-edits\?) (progn (lsp--apply-text-edits additional-text-edits\?))))
  lsp--capf-exit-fn(#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)) finished ["." "\"" "'" "/" "@" "<"])
  apply(lsp--capf-exit-fn (#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)) finished ["." "\"" "'" "/" "@" "<"]))
  (closure ((args ["." "\"" "'" "/" "@" "<"]) (fn . lsp--capf-exit-fn) t) (&rest args-before) (apply fn (append args-before args)))(#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)) finished)
  funcall((closure ((args ["." "\"" "'" "/" "@" "<"]) (fn . lsp--capf-exit-fn) t) (&rest args-before) (apply fn (append args-before args))) #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)) finished)
  (if exit-function (funcall exit-function arg (if (= (car (completion-boundaries arg table nil "")) (length arg)) 'sole 'finished)))
  (let* ((res company-capf--current-completion-data) (exit-function (plist-get (nthcdr 4 res) :exit-function)) (table (nth 3 res))) (if exit-function (funcall exit-function arg (if (= (car (completion-boundaries arg table nil "")) (length arg)) 'sole 'finished))))
  company--capf-post-completion(#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  (cond ((eq command 'interactive) (company-begin-backend 'company-capf)) ((eq command 'prefix) (let ((res (company--capf-data))) (if res (progn (let ((length ...) (prefix ...)) (cond (... ...) (length ...) (t prefix))))))) ((eq command 'candidates) (company-capf--candidates arg)) ((eq command 'sorted) company-capf--sorted) ((eq command 'match) (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data) :company-match))) (if f (funcall f arg) (let* ((match-start nil) (pos -1) (prop-value nil) (faces nil) (has-face-p nil) chunks (limit (length arg))) (while (< pos limit) (setq pos (if ... 0 ...)) (setq prop-value (or ... ...) faces (if ... prop-value ...) has-face-p (memq ... faces)) (cond (... ...) (... ... ...))) (nreverse chunks))))) ((eq command 'duplicates) t) ((eq command 'no-cache) t) ((eq command 'meta) (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data) :company-docsig))) (if f (progn (funcall f arg))))) ((eq command 'doc-buffer) (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data) :company-doc-buffer))) (if f (progn (funcall f arg))))) ((eq command 'location) (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data) :company-location))) (if f (progn (funcall f arg))))) ((eq command 'annotation) (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data) :annotation-function))) (if f (progn (funcall f arg))))) ((eq command 'require-match) (plist-get (nthcdr 4 (company--capf-data)) :company-require-match)) ((or (eq command 'init) (not (eq command 'post-completion))) nil) (t (company--capf-post-completion arg)))
  company-capf(post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  apply(company-capf (post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>))))
  (if (functionp company-backend) (apply company-backend args) (apply #'company--multi-backend-adapter company-backend args))
  (condition-case err (if (functionp company-backend) (apply company-backend args) (apply #'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(post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  apply(company-call-backend-raw (post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>))))
  (let ((value (apply fun args))) (if (not (eq (car-safe value) :async)) value (let ((res 'trash) (start (time-to-seconds))) (funcall (cdr value) #'(lambda (result) (setq res result))) (while (eq res '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 (post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>))) company-capf)
  company-call-backend(post-completion #("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  (let ((company-backend backend)) (run-hook-with-args 'company-completion-finished-hook result) (company-call-backend 'post-completion result))
  (if (stringp result) (let ((company-backend backend)) (run-hook-with-args 'company-completion-finished-hook result) (company-call-backend 'post-completion result)) (run-hook-with-args 'company-completion-cancelled-hook result))
  (progn (if (stringp result) (let ((company-backend backend)) (run-hook-with-args 'company-completion-finished-hook result) (company-call-backend 'post-completion result)) (run-hook-with-args 'company-completion-cancelled-hook result)) (run-hook-with-args 'company-after-completion-hook result))
  (if prefix (progn (if (stringp result) (let ((company-backend backend)) (run-hook-with-args 'company-completion-finished-hook result) (company-call-backend 'post-completion result)) (run-hook-with-args 'company-completion-cancelled-hook result)) (run-hook-with-args 'company-after-completion-hook result)))
  (let ((prefix company-prefix) (backend company-backend)) (setq company-backend nil company-prefix nil company-candidates nil company-candidates-length nil company-candidates-cache nil company-candidates-predicate nil company-common nil company-selection 0 company-selection-changed nil company--manual-action nil company--manual-prefix nil company--point-max nil company-point nil) (if company-timer (progn (cancel-timer company-timer))) (company-echo-cancel t) (company-search-mode 0) (company-call-frontends 'hide) (company-enable-overriding-keymap nil) (if prefix (progn (if (stringp result) (let ((company-backend backend)) (run-hook-with-args 'company-completion-finished-hook result) (company-call-backend 'post-completion result)) (run-hook-with-args 'company-completion-cancelled-hook result)) (run-hook-with-args 'company-after-completion-hook result))))
  company-cancel(#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  company-finish(#("addEnvironment" 0 1 (face (completions-first-difference) lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>) 1 14 (lsp-completion-prefix "" lsp-completion-markers (821 #<marker (moves after insertion) at 835 in TsbRegisterApplicationStack.ts>) lsp-completion-start-point 821 lsp-sort-text "0" lsp-completion-item #<hash-table equal 7/9 0x1fe892e7ce27>)))
  (let ((result (nth company-selection company-candidates))) (company-finish result))
  (progn (let ((result (nth company-selection company-candidates))) (company-finish result)))
  (if (company-manual-begin) (progn (let ((result (nth company-selection company-candidates))) (company-finish result))))
  company-complete-selection()
  funcall-interactively(company-complete-selection)
  call-interactively(company-complete-selection nil nil)
  command-execute(company-complete-selection)
kiennq commented 4 years ago

The log is too long. Can you try to get to repro the issue first, toggle the io trace, try to repro it again and paste the log from there?

yyoncho commented 4 years ago

Also, it will be useful if you can describe steps to reproduce with lsp-start-plain.el.

benwainwright commented 4 years ago

The log is too long. Can you try to get to repro the issue first, toggle the io trace, try to repro it again and paste the log from there?

That's literally what I did. But I'll give it a go and see if it produces a shorter log?

Also, it will be useful if you can describe steps to reproduce with lsp-start-plain.el.

The steps are basically

I can't be more specific than that. As noted above, it appears that using lsp-start-plain.el an error is appearing which might be related, but I can't be certain.

kiennq commented 4 years ago

Thanks, the error is saying [yas] yas-expand-snippet needs properly setup though

yyoncho commented 4 years ago

I was able to reproduce with lsp-start-plain.el but doing C-g in the callstack after closing the callstack buffer after yasnippet exception. But it seems to me that issue is as a side effect from that exception. In your original setup do you have yas-global-mode enabled?

benwainwright commented 4 years ago

I do yes; just to be clear, in my original setup company mode does work for a bit... it just stops working.

benwainwright commented 4 years ago

Ok. I've disabled yas-global-mode for now. First impressions, it definitely seems to be lasting longer than normal; I'll work with it for a bit and see if it sticks.

benwainwright commented 4 years ago

@yyoncho Ok, completely removing yassnippets hasn't resolved the problem. I'll have another go and trying to narrow down the repro tomorrow.

yyoncho commented 4 years ago

I think that at this point it is best to ask @kiennq to provide some tracepoints so we can diagnose the issue. IMO we break due to exception during completion and we(or company?) end up in broken state.

kiennq commented 4 years ago

I'm more curious about if we get any completions from server after this issue occurred. So just trace-io after the we can repo it would be enough. Also, can you dump value of lsp--capf-cache when this issue happens? And try to call lsp--capf-clear-cache to see if it resolves the issue?

yyoncho commented 4 years ago

@kiennq here are steps to reproduce:

  1. Go to lsp-start-plain.el and delete (yas-global-mode) call.
  2. emacs -q -l lsp-start-plain.el js.js
  3. Make sure the server is started and type
var s = "xx"

then type
s.rep and complete the selection.

It will show an error press q. Go on the next line and try again s.rep - it does not show completion.

kiennq commented 4 years ago

Okay, clear cache will fix the issue.

yyoncho commented 4 years ago

Seems like we should have clear cache call in company-completion-started-hook, right?

yyoncho commented 4 years ago
(add-hook 'company-completion-started-hook
          (lambda (&rest _)
            (setq-local lsp-inhibit-lsp-hooks t)
            (lsp--capf-clear-cache))
          nil
          t)

This change seems to be fixing the issue.

kiennq commented 4 years ago

That's not enough. For example you can still see that the completion is not suggested in this case

let stand = "xx"
stand.repeat repe<|>

There will be no candidate being suggested.

kiennq commented 4 years ago

I think the completion start detection in company-mode is not that accurate, we should really wrap to always clean cache when completion completed (which is more accurately detected?)

benwainwright commented 4 years ago

Wow, thanks for the prompt action guys. I'll await that merge and see if it fixes things at my end :)

benwainwright commented 4 years ago

I just nuked my elpa/lsp-mode folder and I don't seem to have gotten the changes. Is there anything I need to get the update?

kiennq commented 4 years ago

You may need to wait a little bit more to get the change, it depends on when MELPA build every packages. Alternatively, you can try quelpa, and type C-u M-x quelpa, select lsp-mode and install it rightaway

benwainwright commented 4 years ago

Ok, the problem appears resolved. Thanks for your help.

benwainwright commented 4 years ago

@kiennq problem is not resolved. Will try to properly rep again tomorrow. Could you reopen issue please?

yyoncho commented 4 years ago

@benwainwright can you try calling (lsp--capf-clear-cache) when you hit the issue? Also, as suggested by @kiennq can you turn on the logs and inspect if M-x company-complete results in textDocument/completion call to the server.

benwainwright commented 4 years ago

@benwainwright can you try calling (lsp--capf-clear-cache) when you hit the issue?

Can confirm that suggestions start working again after I make this function call.

Also, as suggested by @kiennq can you turn on the logs and inspect if M-x company-complete results in textDocument/completion call to the server.

I'll do this later this evening if you still need it (technically working atm), unless the above is enough of a smoking gun for you?

yyoncho commented 4 years ago

I'll do this later this evening if you still need it (technically working atm), unless the above is enough of a smoking gun for you?

There is no need for that. Apparently the exit function is not called. Can you test with the following change:

(defun lsp--clean-company ()
  (remove-hook 'company-completion-started-hook
               (lambda (&rest _)
                 (lsp--capf-clear-cache)
                 (setq-local lsp-inhibit-lsp-hooks t))
               t)
  (remove-hook 'company-after-completion-hook
               (lambda (&rest _)
                 (lsp--capf-clear-cache)
                 (setq-local lsp-inhibit-lsp-hooks nil))
               t))

This will force cleanup on startup.

benwainwright commented 4 years ago

Ok, I've put that in my config and I'll continue to work and see if it resolves the issue.

kiennq commented 4 years ago

@benwainwright Do you also encounter any error when completion stops working?

yyoncho commented 4 years ago

@benwainwright any update?

benwainwright commented 4 years ago

Apologies for the delay; I've been quite busy at work. I've got a bit of time now; will confirm

benwainwright commented 4 years ago

Ok, this is what the my lsp-mode configuration looks like:

(use-package lsp-mode
  :ensure t
  :config
  (setenv "TSSERVER_LOG_FILE" "/tmp/tsserver.log")
  (add-hook 'go-mode-hook #'lsp)
  (add-hook 'js-mode-hook #'lsp)
  (add-hook 'web-mode-hook #'lsp)
  (add-hook 'typescript-mode-hook #'lsp)
  (add-hook 'python-mode-hook #'lsp)
  (defun lsp--clean-company ()
    (remove-hook 'company-completion-started-hook
         (lambda (&rest _)
           (lsp--capf-clear-cache)
           (setq-local lsp-inhibit-lsp-hooks t))
         t)
    (remove-hook 'company-after-completion-hook
         (lambda (&rest _)
           (lsp--capf-clear-cache)
           (setq-local lsp-inhibit-lsp-hooks nil))
         t)))

Unfortunately, the issue is still appearing; even though calling the function that you suggestion manually still appears to solve the issue.

yyoncho commented 4 years ago

can you check if company-completion-started-hook is the correct one when you are in the buffer?

benwainwright commented 4 years ago
company-completion-started-hook is a variable defined in ‘company.el’.
Its value is
(#f(compiled-function
    (&rest _)
    #<bytecode 0x1ead3174ee7be37c>)
   t)
Original value was nil
Local in buffer HttpCommandBus.ts; global value is nil

@yyoncho I'm guessing this means no?

benwainwright commented 4 years ago

Perhaps I'm configuring this incorrectly?

yyoncho commented 4 years ago

can you replace the function directly in lsp-mode.el and then bytecompile the file with M-x byte-compile-file? Then restart emacs.

benwainwright commented 4 years ago

Ok; I've done that. At first appearance it appears to be working. Let me try it for a more protracted period at work tomorrow to confirm.

yyoncho commented 4 years ago

I am marking this as closed, please reopen if #1887 is not suffient.

benwainwright commented 4 years ago

Ok, so it's been reverted. Is there any other potential fixes I can try?

yyoncho commented 4 years ago

I believe the fix works but results in one more call to the server.

benwainwright commented 4 years ago

@yyoncho Ok. But at the moment things are still breaking for me, and I can't believe this isn't coming up for many others. Is there no alternative fix that doesn't do that?

rrudakov commented 4 years ago

Hi, everyone. I don't know if it's related, but for me completion stops working in lsp-java after some time as well. As I can see from *lsp-log* it seems like client doesn't send document/completion request anymore. lsp-workspace-restart doesn't help, only restarting emacs. Maybe I should open separate issue?

EDIT: the rest functionality is working perfectly (code actions, diagnostics etc...)

*lsp-log*:

Jul 7, 2020, 10:48:38 AM >> workspace/didChangeWatchedFiles 
Jul 7, 2020, 10:48:38 AM begin problem for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:48:38 AM 0 problems reported for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:48:38 AM >> workspace/didChangeWatchedFiles 
Jul 7, 2020, 10:48:38 AM >> workspace/didChangeWatchedFiles 
Jul 7, 2020, 10:48:38 AM begin problem for /TestProperties.java
Jul 7, 2020, 10:48:38 AM 0 problems reported for /TestProperties.java
Jul 7, 2020, 10:48:38 AM Validated 1. Took 75 ms
Jul 7, 2020, 10:49:05 AM >> workspace/didChangeWatchedFiles 
Updating integration-tests configuration[Message]
Jul 7, 2020, 10:49:05 AM Starting Maven update for integration-tests
Jul 7, 2020, 10:49:07 AM Updated integration-tests in 1737 ms
Jul 7, 2020, 10:49:09 AM >> registerFeature 'workspace/didChangeWatchedFiles'
Jul 7, 2020, 10:49:48 AM >> workspace/didChangeWatchedFiles 
Updating integration-tests configuration[Message]
Jul 7, 2020, 10:49:48 AM Starting Maven update for integration-tests
Jul 7, 2020, 10:49:49 AM Updated integration-tests in 1038 ms
Jul 7, 2020, 10:49:51 AM >> registerFeature 'workspace/didChangeWatchedFiles'
Jul 7, 2020, 10:49:52 AM >> document/didChange
Jul 7, 2020, 10:49:53 AM >> document/didChange
Jul 7, 2020, 10:49:53 AM >> document/didChange
Jul 7, 2020, 10:49:53 AM >> document/didChange
Jul 7, 2020, 10:49:53 AM >> document/didChange
Jul 7, 2020, 10:49:53 AM >> document/completion
Jul 7, 2020, 10:49:53 AM Completion request completed

<-- here completion stops working

Jul 7, 2020, 10:49:54 AM >> document/didChange
Jul 7, 2020, 10:49:56 AM >> document/didChange
Jul 7, 2020, 10:49:56 AM >> document/didChange
Jul 7, 2020, 10:49:56 AM >> document/didChange
Jul 7, 2020, 10:49:56 AM >> document/didChange
Jul 7, 2020, 10:49:57 AM >> document/didChange
Jul 7, 2020, 10:49:57 AM >> document/didChange
Jul 7, 2020, 10:49:57 AM >> document/willSaveWaitUntil
Jul 7, 2020, 10:49:57 AM >> document/didSave
Jul 7, 2020, 10:49:57 AM >> workspace/didChangeWatchedFiles 
Jul 7, 2020, 10:50:08 AM >> document/didChange
Jul 7, 2020, 10:50:08 AM >> document/didChange
Jul 7, 2020, 10:50:08 AM >> document/didChange
Jul 7, 2020, 10:50:08 AM >> document/didChange
Jul 7, 2020, 10:50:08 AM >> document/didChange
Jul 7, 2020, 10:50:09 AM >> document/didChange
Jul 7, 2020, 10:50:09 AM >> document/didChange
Jul 7, 2020, 10:50:13 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:14 AM >> document/didChange
Jul 7, 2020, 10:50:16 AM >> document/didChange
Jul 7, 2020, 10:50:16 AM >> document/didChange
Jul 7, 2020, 10:50:17 AM >> document/didChange
Jul 7, 2020, 10:50:17 AM >> document/didChange
Jul 7, 2020, 10:50:17 AM >> document/didChange
Jul 7, 2020, 10:50:18 AM >> document/didChange
Jul 7, 2020, 10:50:18 AM >> document/didChange
Jul 7, 2020, 10:50:18 AM >> document/didChange
Jul 7, 2020, 10:50:18 AM >> document/didChange
Found the following clients for /home/rrudakov/Work/EPAM/thumbnail-service/integration-tests/src/test/java/com/lgi/thumbnail/miner/mock/hollow/ThumbnailMinerHollowFaker.java: (server-id jdtls, priority 0)
The following clients were selected based on priority: (server-id jdtls, priority 0)
Jul 7, 2020, 10:50:21 AM >> document/didOpen
Jul 7, 2020, 10:50:22 AM Reconciled 0. Took 2 ms
Jul 7, 2020, 10:50:22 AM begin problem for /TestProperties.java
Jul 7, 2020, 10:50:22 AM 0 problems reported for /TestProperties.java
Jul 7, 2020, 10:50:22 AM begin problem for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:50:22 AM 0 problems reported for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:50:22 AM Validated 2. Took 66 ms
Jul 7, 2020, 10:50:24 AM >> document/didChange
Jul 7, 2020, 10:50:24 AM >> document/didChange
Jul 7, 2020, 10:50:24 AM >> document/didChange
Jul 7, 2020, 10:50:24 AM >> document/didChange
Jul 7, 2020, 10:50:25 AM Reconciled 0. Took 6 ms
Jul 7, 2020, 10:50:25 AM begin problem for /TestProperties.java
Jul 7, 2020, 10:50:25 AM 0 problems reported for /TestProperties.java
Jul 7, 2020, 10:50:25 AM begin problem for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:50:25 AM 1 problems reported for /ThumbnailMinerHollowFaker.java
Jul 7, 2020, 10:50:25 AM Validated 2. Took 61 ms
Jul 7, 2020, 10:50:25 AM >> document/didChange
Jul 7, 2020, 10:50:26 AM Reconciled 0. Took 5 ms
Jul 7, 2020, 10:50:26 AM >> document/didChange
Jul 7, 2020, 10:50:26 AM Reconciled 0. Took 3 ms
Jul 7, 2020, 10:50:26 AM >> document/didChange
Jul 7, 2020, 10:50:27 AM Reconciled 0. Took 2 ms
Jul 7, 2020, 10:50:27 AM begin problem for /TestProperties.java
Jul 7, 2020, 10:50:27 AM 0 problems reported for /TestProperties.java
kiennq commented 4 years ago

@benwainwright Can you check if #1896 fixes your issue?

yyoncho commented 4 years ago

This one should be fixed, @benwainwright reopen the issue if you hit it again.

benwainwright commented 4 years ago

Cool I'll have a look this morning :)

ashkan-leo commented 3 years ago

Hello!

I have been experiencing a similar behavior when using lsp-metals to edit Scala source. The completion functionality stopped working a few months ago. I am using Doom Emacs. When I clean the cache by running (setq company--capf-cache nil), sometimes the completion works but most of the time it doesn't. Sometimes I get some garbage completion too, but most of the time I don't get any completion at all. The other functionalities like type inference and goto definition seems to work. I appreciate any help. I have raised this issue in multiple projects past few months with no luck so far

yyoncho commented 3 years ago

@ashkan-leo make sure you are using the latest lsp-mode.

Then: Use M-x company-diag to verify complany completion is using lsp-mode You can also enable logging by setting lsp-print-io to t and then match your typing to textDocument/completion requests and your typing.