nvimdev / lspsaga.nvim

improve neovim lsp experience
MIT License
3.42k stars 286 forks source link

`Lspsaga diagnose_jump_next` error with `'replacement string' item contains newlines` in rust-analyzer lsp #1342

Closed csyJoy closed 10 months ago

csyJoy commented 10 months ago

Describe the bug

while using :Lspsaga diagnose_jump_next in rust project with rust-analyzer lsp, it errors with following error message:

Error executing Lua callback: ...share/nvim/site/lazy/lspsaga.nvim/lua/lspsaga/window.lua:118: 'replacement string' item contains newlines
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ...share/nvim/site/lazy/lspsaga.nvim/lua/lspsaga/window.lua:118: in function 'setlines'
        ...m/site/lazy/lspsaga.nvim/lua/lspsaga/diagnostic/init.lua:313: in function 'render_diagnostic_window'
        ...m/site/lazy/lspsaga.nvim/lua/lspsaga/diagnostic/init.lua:423: in function 'move_cursor'
        ...m/site/lazy/lspsaga.nvim/lua/lspsaga/diagnostic/init.lua:437: in function 'goto_next'
        ...hare/nvim/site/lazy/lspsaga.nvim/lua/lspsaga/command.lua:41: in function <...hare/nvim/site/lazy/lspsaga.nvim/lua/lspsaga/command.lua:40>
        ...hare/nvim/site/lazy/lspsaga.nvim/lua/lspsaga/command.lua:74: in function 'load_command'
        ...cal/share/nvim/site/lazy/lspsaga.nvim/plugin/lspsaga.lua:8: in function <...cal/share/nvim/site/lazy/lspsaga.nvim/plugin/lspsaga.lua:7>

from the stack traceback, I change the function setlines to print the actual line:

function obj:setlines(lines, row, erow)
  row = row or 0
  erow = erow or -1
  vim.print(lines)
  api.nvim_buf_set_lines(self.bufnr, row, erow, false, lines)
  return self
end

lua runtime prints the following line before lspsaga throwing the error as the result of following steps of reproduce

{ "cannot find type `BTreeMap` in this scope", "not found in this scope", "main.rs(1:0): consider importing this struct: `use std::collections::BTreeMap;\n\n`" }

Steps to reproduce

  1. cargo new foo
  2. nvim foo/src/main.rs
  3. replace with the following code
    fn main() {
    let mut bt: BTreeMap<i32, i32> = BTreeMap::new();
    }
  4. save the file and use :Lspsaga diagnose_jump_next in line 2

Expected behavior

Lspsaga spawn error window within error message and code action correctly

Neovim version (nvim -v)

NVIM v0.9.4

lspsaga commit

8b02796

Terminal name/version

alacritty 0.12.3 (5efb069)