Closed thomasheartman closed 3 years ago
I will take a look at this
I've noticed the same error with intelephense
when calling ivy-completion-at-point
while in company-complete
and completing variables.
My error is caused by lsp-completion--clear-cache
, specifically the part where it deletes the markers (set-marker
nil). Removing it fixes my issue, but that is just a debugging workaround. My issue does seem unrelated though.
@nbfalcon Thanks for the input! I can confirm that that does indeed seem to fix the problem :D What are the implications of removing that (set-marker nil)
? Will it cause anything to stop working?
But as you mention, it's not a real fix, but a temporary workaround. I wonder what's causing the issue. Why is the marker being set to nil
in the first place?
Nothing will stop working, but the markers won't get cleaned up, which will cause slowdowns until a GC happens. Emacs might quickly become unresponsive if you use auto-complete a lot.
Actually, my issue might not be unrelated: it seems that in both cases, the marker is reused between multiple invocations of lsp-completion-at-point
which go trough the cache.
@kiennq have you already started working on this? If not, you may assign this to me, since I may have a headstart in debugging.
@nbfalcon Sure, please take it (I think you can just change the assignee by yourself).
I'm not being able to repro this on my env so there's not much actionable from me.
I wrote that code before expecting we have to invalidate the cache in correct time while the marker is not used anymore.
What happens here is that the marker may have been alternated by some other means so it's not become available anymore (anything that modify the buffer before lsp-mode
does when apply edit).
We need the marker so that the insertion by company-mode
(or any other completion rendering framework) can be properly tracked.
@nbfalcon @thomasheartman If you can easily (and 100%) repro this problem, can you take the calling stack for that?
Evaluate something like this
(defsubst logme (&rest args)
"Like `message' with same ARGS but don't echo."
(let ((inhibit-message t))
(apply #'message args)))
(defun log-backtrace (&optional max-depth)
"Print out `backtrace'."
(let ((i 5) (bt t) backtraces
(max-depth (+ 5 (or max-depth 999))))
(logme "%s" backtraces)
(while (and bt (< i max-depth))
(setq bt (backtrace-frame i))
(setq backtraces (nconc backtraces (list bt)))
(cl-incf i))
(->> (mapconcat (lambda (bt) (format "%.100s" (cdr bt)))
backtraces
"\n")
(logme "================ Backtrace ================\n%s")))))
After that insert (log-backtrace)
on lsp-completion--clear-cache
function and repro this problem (the minimal least step repro).
The calling trace will be recorded in *Message*
buffer.
I figure out the issue, when there's only one completion item like in this case, company-mode
actually cancel the completion (not even doing template expansion) thus invalidate the cache.
Nice one! I checked out the PR and can confirm that this indeed seems to fix the issue I've been having. Thanks!
Hi,
I've got an issue with Rust Analyzer's post-completion functions. I previously reported this to Company mode, but was told to take it here.
Describe the bug
When using Rust Analyzer's post-completion functionality, I came across an issue where it seemingly doesn't work unless the previous action removed text from the buffer or there is text following the items to be expanded.
More specifically, given this scenario (inside a function and where
|
is the cursor):I can trigger
company-complete
to get the list of completion candidates (which contains a single item). If I try tocompany-complete-selection
, I get an error message sayingHowever, if I add a character and then delete it, say
true.if
->true.ifh
->true.if
, expanding the snippet works just fine, expanding toThe same happens if what I delete is elsewhere in the buffer too (such as on a different line) and it doesn't seem to matter what character it is (whitespace or otherwise).
Also, it turns out that as long as I enter any characters after
if
(e.g.true.ifh
) and move the cursor back to before the extra characters, expansions works as expected and removes the remaining characters:true.if|h
->company-complete-selection
becomesIf a string follows the
if
, then it remains intact for some reason.true.if"string"
becomes:To Reproduce
Sample project: https://github.com/thomasheartman/lsp-rust-analyzer-post-completion-issue
The sample project is a fresh rust project (as created by
cargo new
). Insrc/main.rs
, line 6 istrue.if
. Expanding this snippet may or may not work based on previous action. It seems to always work if I delete characters before expanding. It never works if I try and expand it just after typing it out.Expected behavior
I expect the post-completion to work regardless of what my previous action in the buffer was, and especially if I have just typed out the necessary letters for expansion to take place. I expect it to not throw any errors.
Which Language Server did you use Rust Analyzer (as of 2020-11-09).
OS NixOS 20.09
Error callstack
Callstack
``` Debugger entered--Lisp error: (error "Marker does not point anywhere") delete-region(271 #`*lsp-log*`
``` Command "rls" is not present on the path. Command "/home/thomas/.emacs.d/.cache/lsp/rust/rust-analyzer" is present on the path. Command "rls" is not present on the path. Command "/home/thomas/.emacs.d/.cache/lsp/rust/rust-analyzer" is present on the path. Found the following clients for /home/thomas/projects/rust-analyzer-setup/src/main.rs: (server-id rust-analyzer, priority 1) The following clients were selected based on priority: (server-id rust-analyzer, priority 1) Command "rls" is present on the path. Command "/nix/store/99y2l9alga74r3fzd55a8y7nkzw0qzd8-rust-analyzer-unstable-2020-08-24/bin/rust-analyzer" is present on the path. Command "rls" is present on the path. Command "/nix/store/99y2l9alga74r3fzd55a8y7nkzw0qzd8-rust-analyzer-unstable-2020-08-24/bin/rust-analyzer" is present on the path. Found the following clients for /home/thomas/projects/rust-analyzer-setup/src/main.rs: (server-id rls, priority -1), (server-id rust-analyzer, priority 1) The following clients were selected based on priority: (server-id rust-analyzer, priority 1) Creating watch for /home/thomas/projects/rust-analyzer-setup Creating watch for /home/thomas/projects/rust-analyzer-setup/src Command "rls" is present on the path. Command "/nix/store/99y2l9alga74r3fzd55a8y7nkzw0qzd8-rust-analyzer-unstable-2020-08-24/bin/rust-analyzer" is present on the path. Command "rls" is present on the path. Command "/nix/store/99y2l9alga74r3fzd55a8y7nkzw0qzd8-rust-analyzer-unstable-2020-08-24/bin/rust-analyzer" is present on the path. Found the following clients for /home/thomas/projects/lsp-post-completion/src/main.rs: (server-id rls, priority -1), (server-id rust-analyzer, priority 1) The following clients were selected based on priority: (server-id rust-analyzer, priority 1) Creating watch for /home/thomas/projects/lsp-post-completion Creating watch for /home/thomas/projects/lsp-post-completion/src Cancelling textDocument/onTypeFormatting(97) in hook after-change-functions Cancelling textDocument/codeAction(145) in hook after-change-functions Cancelling textDocument/hover(159) in hook after-change-functions Cancelling textDocument/codeAction(158) in hook after-change-functions Cancelling textDocument/hover(176) in hook after-change-functions Cancelling textDocument/hover(206) in hook after-change-functions Cancelling textDocument/hover(211) in hook after-change-functions Cancelling textDocument/codeAction(210) in hook after-change-functions Cancelling textDocument/hover(218) in hook after-change-functions Cancelling textDocument/codeAction(217) in hook after-change-functions Cancelling textDocument/hover(226) in hook after-change-functions Cancelling textDocument/documentHighlight(225) in hook after-change-functions Cancelling textDocument/codeAction(224) in hook after-change-functions Cancelling textDocument/codeAction(327) in hook after-change-functions ```The
lsp-workspace-show-log
output was too long to include in this comment. I'll try and put it in a separate comment.Versions
Reproducing the issue in a clean environment:
I tried reproducing the issue in a clean environment but wasn't able to install the correct major mode. I'm not sure why or what's going on. If there is a simple solution, I'd be more than happy to try again. I've included the error message below.
Install error message
``` Debugger entered--Lisp error: (wrong-type-argument stringp nil) string-match("\\`https?:" nil nil) package--with-response-buffer-1(nil #f(compiled-function () #