-
-
Notifications
You must be signed in to change notification settings - Fork 912
lsp--document-highlight fails if textDocument/documentHighlight is not supported #2378
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
Comments
Willing to open a PR? In general, we are not supposed to call that method at all when |
Yes, I would send a PR. I've dug a little bit deeper and I think this is the code path that adds the function:
Don't care about the error. Is caused by my debugging code. This is the return value of
Does the detection of a not available feature happen after the first request? Must the function get unbound from the hook when this happens? |
This means that highlights are supported.
Can you elaborate? I am interested in the value of |
This case is very difficult, but after a long research I've got all pieces together. The core of the problem is desktop-save-mode. In desktop-restore-file-buffer it does: (let* ((auto-insert nil) ; Disable auto insertion
(coding-system-for-read
(or coding-system-for-read
(cdr (assq 'buffer-file-coding-system
desktop-buffer-locals))))
(buf (find-file-noselect buffer-filename :nowarn)))
(condition-case nil
(switch-to-buffer buf)
(error (pop-to-buffer buf)))
(and (not (eq major-mode desktop-buffer-major-mode))
(functionp desktop-buffer-major-mode)
(funcall desktop-buffer-major-mode)) It opens the file and if the major-mode do not match the saved major mode, it switches. A few weeks ago, I've installed rustic-mode and lsp-mode via package-list-packages. Rustic sets itself as the major mode for rs files and starts lsp on startup. Some of my open buffers are still using rust-mode. Hence, desktop-mode reopens a file that triggers rustic and lsp. Lsp starts the rls and sets the buffer local variable lsp--buffer-workspaces. But because the major mode mismatch desktop-mode switches to rust-mode and this calls (prog-mode → fundamental-mode →) kill-all-local-variables which removes lsp--buffer-workspaces, while the timer stay active. And the rest of the story is obvious: the timer gets triggered, pulls lsp--buffer-workspaces and ends with error in lsp--send-request-async. At least, I would suggest the following change to detect such missettings, but I'm not really familiar with Emacs and would hope there's a hook where lsp can get a message to unset it's timer or bind the timer to a local variable that becomes killed, too. diff --git i/lsp-mode.el w/lsp-mode.el
index 8d0d5e99..b7b9c2cd 100644
--- i/lsp-mode.el
+++ w/lsp-mode.el
@@ -4284,6 +4284,7 @@ Added to `after-change-functions'."
(equal buffer (current-buffer))
(not lsp-inhibit-lsp-hooks)
lsp-managed-mode)
+ (lsp--cur-workspace-check)
(run-hooks 'lsp-on-idle-hook)))
(defun lsp--on-change-debounce (buffer) |
Thank you, this is was a really tricky thing to find! It seems to me that we should use change-major-mode-hook which is called in kill-all-local-variables to call lsp-disconnect. |
What do you think about this change? Is it right? diff --git i/lsp-mode.el w/lsp-mode.el
index 63fafe02..dbc63036 100644
--- i/lsp-mode.el
+++ w/lsp-mode.el
@@ -4284,6 +4284,7 @@ Added to `after-change-functions'."
(equal buffer (current-buffer))
(not lsp-inhibit-lsp-hooks)
lsp-managed-mode)
+ (lsp--cur-workspace-check)
(run-hooks 'lsp-on-idle-hook)))
(defun lsp--on-change-debounce (buffer)
@@ -7820,6 +7821,7 @@ argument ask the user to select which language server to start."
(lsp--try-project-root-workspaces (equal arg '(4))
(and arg (not (equal arg 1))))))
(lsp-mode 1)
+ (add-hook 'change-major-mode-hook 'lsp-disconnect t t)
(when lsp-auto-configure (lsp--auto-configure))
(setq lsp-buffer-uri (lsp--buffer-uri))
(lsp--info "Connected to %s." |
Looks good to me. I would put it in lsp-managed-mode and add also remove-hook when lsp-managed mode is turned off. |
Pushed a fix. Please let me know if it works. Thank you for your analysis once again, it was really helpful. |
I'm getting this error with Haskell. It works fine on the first .hs file I open, but every other .hs file in the workspace after that first one, I get this error. I don't use desktop-save-mode, btw. |
are you on the latest melpa version? |
Yep. |
@spacekitteh I've written up my research for the cause of this bug. https://jo-so.de/2020-12/Emacs-CPU-Verbrauch.html#verbrauchersucheimemacs Maybe you can use a translator to read it. In the end, I used this code in my init.el to analyze what's happening. This creates large logs, so maybe only use lsp-mode in one buffer. (require 'lsp-mode)
(with-eval-after-load 'lsp-mode
(let ((trace-buf "*trace*")
(ctx
(lambda ()
(format
" <+<%s|+|%s|+|%s|+|%s|+|%s>+>"
(buffer-name)
(local-variable-p 'lsp--cur-workspace)
(local-variable-p 'lsp--buffer-workspaces)
lsp--cur-workspace lsp--buffer-workspaces)))
(watcher
(lambda (symbol newval operation where)
(let ((buf (buffer-name)))
(with-current-buffer "*trace*"
(goto-char (point-max))
(insert (format "==>> %s|-|%s|-|%s|-|%s|-|%s|-|%s\n"
buf where symbol
(local-variable-p symbol)
operation (if newval "*val*")))
;; (when (and (not (string-match-p "\.rs$" buf))
;; )
;; (error "open back trace 1"))
))
;; (when (string= operation "makunbound")
;; (error "open back trace 2"))
;; (when (and (eq symbol 'lsp--buffer-workspaces)
;; (string= operation "set")
;; (if newval t))
;; (error "open back trace 3"))
))
)
(get-buffer-create trace-buf)
(trace-function-background 'lsp-feature? trace-buf ctx)
(trace-function-background 'lsp--find-workspaces-for trace-buf ctx)
(add-variable-watcher 'lsp--cur-workspace watcher)
(add-variable-watcher 'lsp--buffer-workspaces watcher)
)) |
@spacekitteh do you use
|
I don't, but I tried anyway, and that didn't fix it (also, the files I'm opening aren't empty). |
@spacekitteh are you able to reproduce with |
@spacekitteh try removing the haskell workspace and adding it again: |
That didn't work. I did notice this though:
and
|
I'll try in the next few days. |
Describe the bug
I get this error message for a Rust file that uses rls:
This is the backtrace of the error:
Which Language Server did you use
Rust
OS
Linux/Debian, GNU Emacs 27.1, lsp-mode 20201129.1832 (from melpa)
Suggested fix
The text was updated successfully, but these errors were encountered: