erlang-ls / erlang_ls

The Erlang Language Server
https://erlang-ls.github.io/
Apache License 2.0
620 stars 136 forks source link

Error when pasting more than 2 lines using Eglot #1427

Closed cfclavijo closed 5 months ago

cfclavijo commented 1 year ago

Describe the bug When pasting multiple lines (more than 2), erlang_ls server fails to process the request and as a result, the editor and the server end up out of sync.

To Reproduce Emacs configured with Eglot as lsp client, erlang_ls.config configured with incremental_sync=true, paste a block of code with more than 2 lines.

I captured a failing request and narrowed the call so the problem can be replicated with: els_text:apply_edits(<<"-module(rgoto_v1_http).\n-export([ get/2]).\n\nget([<<\"account\">>] = _Path, Req) ->\n ct:pal(\"wooooooooooo\"),\n {200, #{<<\"content-type\">> => <<\"text/plain\">>}, <<\"REST Hello World as text!\">>, Req};\n\nget([Value], Req) ->\n {200, #{<<\"content-type\">> => <<\"text/plain\">>}, <<\"REST Hello \",Value/binary,\" as text!\">>, Req}.\n">>, [{#{from => {6,0},to => {6,0}}, "get([<<\"ACCOUNT\">>] = _Path, Req) ->\n ct:pal(\"WOOOOOOOOOOO\"),\n {200, #{<<\"CONTENT-TYPE\">> => <<\"text/plain\">>}, <<\"REST HELLO WORLD AS TEXT!\">>, Req};"}, {#{from => {6,0},to => {8,89}}, "get([<<\"ACCOUNT\">>] = _Path, Req) ->\n ct:pal(\"WOOOOOOOOOOO\"),\n {200, #{<<\"CONTENT-TYPE\">> => <<\"text/plain\">>}, <<\"REST HELLO WORLD AS TEXT!\">>, Req};"}]).

Expected behavior Server should be able to process the request so it keeps in sync with the client

Actual behavior Eglot Client sends a textDocument/didChange with 2 or 3 contentChanges when pasting a block of code with more than 2 lines, the server process the first contentChange* but fails to process the subsequent ones, as a consequence, the internal representation of the document on the server side is not altered, but it is in the editor (emacs).

Context