latex-lsp / texlab

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

Compilation doesn't terminate until previewer is closed #588

Closed potamides closed 2 years ago

potamides commented 2 years ago

First, thank you for this awesome project, it made writing my thesis a fun undertaking! I was able to reproduce my problem with the following minimal configuration:

latexmkrc:

$pdf_mode = 4;
$pdf_previwer = 'start qpdfview --unique %S';

LSP configuration (through nvim-lspconfig):

settings = {
  texlab = {
    build = {
      args = {"-interaction=nonstopmode", "-synctex=1", "-pv", "%f"},
      forwardSearchAfter = false
    }
  }
}

The issue I have seems to manifest itself when I configure a previewer to run on build (i.e. using the -pv flag). Latexmk seems to be running fine but texlab only reports successful (or unsuccessful) compilation back to my editor when I close the preview window. When I look at the LSP logs it seems that these two messages are only sent after the preview window is closed:

[DEBUG][2022-03-28 12:19:01] .../vim/lsp/rpc.lua:454    "rpc.receive"   {  jsonrpc = "2.0",  method = "$/progress",  params = {    token = "texlab-build-1166aa7e-9700-4f34-9009-2e376db35e20",    value = {      kind = "end"    }  }}
[DEBUG][2022-03-28 12:19:01] .../vim/lsp/rpc.lua:454    "rpc.receive"   {  id = 3,  jsonrpc = "2.0",  result = {    status = 0  }}

Interestingly, when I use a single previewer instance and the previewer is already open then it works just fine.

pfoerster commented 2 years ago

Thanks for the report!

It looks like it has to with the capturing the output of the latexmk process. The stdio and stderr streams are not closed when latexmk exits. I think that qpdfview inherits the streams which causes the problem.

I am working on a fix.

pfoerster commented 2 years ago

I am working on a fix.

c9f3fd2 should prevent this issue. When the process has exited, the output capturing is stopped and texlab should no longer wait indefinitely for a response.

First, thank you for this awesome project, it made writing my thesis a fun undertaking!

You’re welcome!

potamides commented 2 years ago

https://github.com/latex-lsp/texlab/commit/c9f3fd2738fb15150fad0540b18095ed79276b8f should prevent this issue.

Awesome! I gave it a run and it indeed seems to fix my issue. However, interestingly my "quickfix" I used to circumvent this bug earlier stopped working. Consider the following configuration, where I instead of previewing through -pv execute a forward search after compiling:

settings = {
  texlab = {
    build = {
      args = {"-interaction=nonstopmode", "-synctex=1", "%f"},
      forwardSearchAfter = true
    },
    forwardSearch = {
      executable = "qpdfview",
      args = {"--unique", "%p#src:%f:%l:1"}
    }
  }
}

If I now repeatedly trigger textDocument/build, texlab stops responding after a while and sometimes doesn't even open qpdfview. If this bug is not related, please let me know and I'll open a separate issue.

pfoerster commented 2 years ago

Can you try out 14c981d4420857cb172be60d595da4bb2899a1b7, please?

potamides commented 2 years ago

I tried it and now everything seems to work as expected.