PerlNavigator icon indicating copy to clipboard operation
PerlNavigator copied to clipboard

Obscure formatting issue with Neovim

Open WhoIsSethDaniel opened this issue 2 years ago • 1 comments

This may be specific to Neovim, but I don't know if it's a bug with Neovim or not.

Given this perl file:

#!/usr/bin/env perl

content;

If I now try to format this file the following is logged by Neovim to its LSP log:

[DEBUG][2022-03-17 21:02:15] .../lua/vim/lsp.lua:1023   "LSP[perlnavigator]"    "client.request"        1       "textDocument/formatting"       {
  options = {
    [""] = true,
    insertSpaces = false,
    tabSize = 8
  },
  textDocument = {
    uri = "file:///home/seth/src/toy/perl/t"
  }
}       <function 1>    1
[DEBUG][2022-03-17 21:02:15] .../vim/lsp/rpc.lua:347    "rpc.send"      {
  id = 2,
  jsonrpc = "2.0",
  method = "textDocument/formatting",
  params = {
    options = {
      [""] = true,
      insertSpaces = false,
      tabSize = 8
    },
    textDocument = {
      uri = "file:///home/seth/src/toy/perl/t"
    }
  }
}
[DEBUG][2022-03-17 21:02:15] .../vim/lsp/rpc.lua:454    "rpc.receive"   {
  id = 7,
  jsonrpc = "2.0",
  method = "workspace/workspaceFolders"
}
[TRACE][2022-03-17 21:02:15] .../lua/vim/lsp.lua:806    "server_request"        "workspace/workspaceFolders"    nil
[TRACE][2022-03-17 21:02:15] .../lua/vim/lsp.lua:809    "server_request: found handler for"     "workspace/workspaceFolders"
[TRACE][2022-03-17 21:02:15] ...lsp/handlers.lua:487    "default_handler"       "workspace/workspaceFolders"    {
  ctx = '{\n  client_id = 1,\n  method = "workspace/workspaceFolders"\n}'
}
[DEBUG][2022-03-17 21:02:15] .../vim/lsp/rpc.lua:464    "server_request: callback result"       {
  result = vim.NIL,
  status = true
}
[DEBUG][2022-03-17 21:02:15] .../vim/lsp/rpc.lua:347    "rpc.send"      {
  id = 7,
  jsonrpc = "2.0",
  result = vim.NIL
}
[ERROR][2022-03-17 21:02:15] .../vim/lsp/rpc.lua:73     "invalid header line %q"        "content;\nee4ffa34-a14f-4609-b2e4-bf23565f3262\nContent-Length: 157"

The last line is the error. I found this, not with the above file, but with a much more complicated file that had the word content in a couple of lines that looked like this:

  my ($body)
          = map { $_->content } $sent[0]{email}->object->parts;

I don't know if it's how the content is being sent, or what. I couldn't get any other LSP server to fail with the word content somewhere in it. Only PerlNavigator had this particular issue.

This is with the most recently published npm of PerlNavigator. Which I believe is 0.2.8.

WhoIsSethDaniel avatar Mar 18 '22 02:03 WhoIsSethDaniel

I also tried it with the 0.2.10 downloadable executable with the same results.

WhoIsSethDaniel avatar Mar 18 '22 02:03 WhoIsSethDaniel

For the record: I am having this issue with formatting also.

It is literally crippling my workflow.

Now, this does seem to be a bug in neovim (see neovim/neovim#15444); but the comments there seem to say this only happens if the LSP is sending things before the headers that it's supposed to send.

@bscan is there a way to see the requests that the server is sending to debug this further?

rabbiveesh avatar Jan 10 '23 15:01 rabbiveesh

@rabbiveesh I work around this by disabling formatting via perlnavigator and using null-ls to run perltidy. It works well.

WhoIsSethDaniel avatar Jan 10 '23 15:01 WhoIsSethDaniel

Thanks @rabbiveesh ! Between your comments and @WhoIsSethDaniel 's debug log, I now see the error. This issue never manifested in vscode because vscode uses node-ipc for interprocess communication, while most of the other editors use stdin/stdout.

Anything printed to the console via console.log is written to stdout and pollutes the communication (stated here too: https://github.com/microsoft/vscode-languageserver-node/issues/824#issuecomment-938392051 ). In this case it was printing the entire output of perltidy to stdout, which was showing up before sending the response headers. Should be fixed via https://github.com/bscan/PerlNavigator/commit/ae8dde13aa21a0c8c28e0db9e538630626bab225 . I just deployed to NPM as v0.4.8. Thank you both for helping debug this.

bscan avatar Jan 12 '23 13:01 bscan