Skip to content
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

Lsp panics after deleting last line of a file #1094

Open
mrghosti3 opened this issue Apr 25, 2024 · 4 comments
Open

Lsp panics after deleting last line of a file #1094

mrghosti3 opened this issue Apr 25, 2024 · 4 comments
Labels
bug Something isn't working needs more info Issue requires more information from poster

Comments

@mrghosti3
Copy link

Environment

  • OS: Linux
  • Editor: neovim v0.9.5
  • LSP version: v5.15

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:

Some(range) => {
let range = document.line_index.offset_lsp_range(range).unwrap();
workspace.edit(&uri, range, &change.text);
}

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

fn offset_lsp_range(&self, line_col: Range) -> Option<TextRange> {
let start = self.offset_lsp(line_col.start)?;
let end = self.offset_lsp(line_col.end)?;
Some(TextRange::new(start, end))
}

@pfoerster
Copy link
Member

@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.

@pfoerster pfoerster added bug Something isn't working needs more info Issue requires more information from poster labels Apr 27, 2024
@mrghosti3
Copy link
Author

Here is the log:
texlab.log

@pfoerster
Copy link
Member

@mrghosti3 Thanks for the log file!

This looks oddly similar to neovim/neovim#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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs more info Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants