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.8k stars 891 forks source link

Args out of range: #<buffer test.c> error while trying to paste #1854

Closed Omerktn closed 4 years ago

Omerktn commented 4 years ago

Hello,

Describe the bug When I try to paste a line, my cursor teleports to elsewhere and unrelated code errors shows up. This is a short video of this error: https://streamable.com/9p3izv I have to kill the buffer and re-open it again to dismiss errors that should not be there.

To Reproduce In the video I'm copying one of the "int test_x = 2;" line, and pasting to the next line.

#include <stdio.h>

int main() {
  printf("Test\n");

int test_1 = 2;
int test_2 = 3;
int test_3 = 3;

  return 0;
}

Expected behavior I'm just expecting paste whatever copied and that's it.

Which Language Server did you use LSP-clangd

OS It's Ubuntu 20.04, Windows Subsystem for Linux with xfce4 GUI desktop

Error callstack This is how lsp-logs look like after pressing C-y : https://paste.ubuntu.com/p/t7BXGGPMB7/

This is what Messages look like, while I'm doing copy and pasting.

Applying 2 edits to `test.c' ...done
c-append-to-state-cache: Args out of range: #<buffer test.c>, 282, 285
Mark set
LSP :: Applying 14 edits to `test.c' ...
Applying 14 edits to `test.c' ...done
lsp--text-document-content-change-event: Args out of range: #<buffer test.c>, 280, 281
Mark set
LSP :: Applying 16 edits to `test.c' ...
Applying 16 edits to `test.c' ...done
c-append-to-state-cache: Args out of range: #<buffer test.c>, 279, 282
Mark set
lsp-request: onDocumentRangeFormatting called for non-added file
Mark set
lsp-request: onDocumentRangeFormatting called for non-added file

This is my .spacemacs file in case needed.

I'd really appreciate it if you can help me.

yyoncho commented 4 years ago

Please provide call stack as described in the bug template.

Omerktn commented 4 years ago

Please provide call stack as described in the bug template.

I updated the issue. Sorry about that.

yyoncho commented 4 years ago

Sorry, this is not error calstack. The callstack could be obtained after doing M-x toggle-debug-on-error and then reproducing the error.

yyoncho commented 4 years ago

This will most likely fix your issue:

(dolist (func '(yank yank-pop evil-paste-before evil-paste-after))
  (advice-remove func  #'spacemacs//yank-indent-region))
Omerktn commented 4 years ago

This will most likely fix your issue:

(dolist (func '(yank yank-pop evil-paste-before evil-paste-after))
  (advice-remove func  #'spacemacs//yank-indent-region))

Interestingly, this solved some issuse of copying & pasting but some other errors stays still.

For example, when I try to type under "#include ", my cursor teleports to the beginning of the file and I get "Redifinition of main()" error. And this is the call stack:

Debugger entered--Lisp error: (error "trying to get preamble for non-added document")
  signal(error ("trying to get preamble for non-added document"))
  error("trying to get preamble for non-added document")
  lsp-request-while-no-input("textDocument/completion" (:textDocument (:uri "file:///home/omer/Documents/test.c") :position (:line 12 :character 10) :context #<hash-table equal 1/65 0x337faad>))
  #f(compiled-function () #<bytecode 0x337f9f1>)()
  #f(compiled-function (probe pred action) #<bytecode 0x337fa11>)("x4" nil t)
  all-completions("x4" #f(compiled-function (probe pred action) #<bytecode 0x337fa11>) nil)
  completion-pcm--all-completions("" ("x4" point) #f(compiled-function (probe pred action) #<bytecode 0x337fa11>) nil)
  completion-basic-all-completions("x4" #f(compiled-function (probe pred action) #<bytecode 0x337fa11>) nil 2)
  #f(compiled-function (style) #<bytecode 0x337fa89>)(basic)
  completion--some(#f(compiled-function (style) #<bytecode 0x337fa89>) (basic partial-completion emacs22))
  completion--nth-completion(2 "x4" #f(compiled-function (probe pred action) #<bytecode 0x337fa11>) nil 2 (metadata (category . lsp-capf) (display-sort-function . identity)))
  completion-all-completions("x4" #f(compiled-function (probe pred action) #<bytecode 0x337fa11>) nil 2 (metadata (category . lsp-capf) (display-sort-function . identity)))
  company-capf--candidates("x4")
  company-capf(candidates "x4")
  apply(company-capf (candidates "x4"))
  company-call-backend-raw(candidates "x4")
  company--fetch-candidates("x4")
  company-calculate-candidates("x4" nil)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer test.c> #<window 3 on test.c> 3312 181)
  apply(company-idle-begin (#<buffer test.c> #<window 3 on test.c> 3312 181))
  timer-event-handler([t 24314 650 794977 nil company-idle-begin (#<buffer test.c> #<window 3 on test.c> 3312 181) nil 0])

I can open a new issue for these errors it you want.

Omerktn commented 4 years ago

Restarting with fresh .spacemacs file fixed the issue. Still don't know what caused the problem. I'm closing the issue, thank you.