latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.5k stars 51 forks source link

Lsp panics after deleting last line of a file #1094

Closed mrghosti3 closed 1 month ago

mrghosti3 commented 4 months ago

Environment

Description

To get this error, follow these steps:

  1. Open tex file in editor;
  2. Copy and paste the whole contents of file;
  3. Go to the last line and delete it;
  4. Check the lsp logs for error.

This doesn't seem like a editor specific error, but could be wrong so more testing from others would be appreciated.

Backtrace:

[ERROR][2024-04-25 18:53:28]
.../vim/lsp/rpc.lua:734
"rpc"

"/usr/bin/env"

"stderr"

0: rust_begin_unwind
    at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
1: core::panicking::panic_fmt
    at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
2: core::panicking::panic
    at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:144:5
3: core::option::unwrap_failed
    at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:1978:5
4: texlab::server::Server::did_change
5: texlab::server::dispatch::NotificationDispatcher::on
6: texlab::server::Server::run
7: texlab::server::Server::exec
8: texlab::main

More detailed backtrace in text file: trace.log

Did some minor investigation and the issue lies here:

https://github.com/latex-lsp/texlab/blob/8a66d053e498c217acda9f238993ac4973c69036/crates/texlab/src/server.rs#L384-L387

Though from the backtrace, it is unclear where the problem comes into existence:

https://github.com/latex-lsp/texlab/blob/8a66d053e498c217acda9f238993ac4973c69036/crates/texlab/src/util/line_index_ext.rs#L26-L30

pfoerster commented 4 months ago

@mrghosti3 Can you create a log file using texlab -vvvv --log-file /path/to/texlab.log please? It looks like the server and the editor have different understandings of the line/column to offset translation.

mrghosti3 commented 4 months ago

Here is the log: texlab.log

pfoerster commented 4 months ago

@mrghosti3 Thanks for the log file!

This looks oddly similar to https://github.com/neovim/neovim/issues/27383.

Input file:

  0    \usepackage[unicode,colorlinks=false]{hyperref}
  1    \usepackage[utf8x]{inputenc}
  2    \usepackage[L7x]{fontenc}
...
102    }{\end{list}\end{mdframed}\par}
103

Change notification:

{
  "contentChanges": [
    {
      "range": {
        "end": { "character": 0, "line": 104 },
        "start": { "character": 0, "line": 103 }
      },
      "text": "",
      "rangeLength": 1
    }
  ],
  "textDocument": {
    "version": 8,
    "uri": "file:///ddisk/uni/coding/ReportAndSlideTemplates/Examples/allPacks.tex"
  }
}

The start position is located after last character of the document (the final newline), the end position on the line below it (but this does not exist). This seems wrong. In my opinion, it should be the last character of line 102 to the first character of line 103 instead so that the change deletes the last newline between line 102 and line 103 (there is no line 104 in this document).

mrghosti3 commented 4 months ago

Indeed it does look like it could be an issue on the editor side. Though would be good to get someones feedback from a different editor, just in case. Perhaps this issue could remain open until there's an update on the one you mentioned?

tomtomjhj commented 1 month ago

Please test https://github.com/neovim/neovim/pull/29904

mrghosti3 commented 1 month ago

@tomtomjhj sorry for the late response.

It seems to be fixed and texlab doesn't crash anymore.