quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
341 stars 28 forks source link

Issue with Quarto LSP. Pandoc hangs when requesting completion and consumes memory and cpu until killed when using static code blocks in a certain way. #397

Open fmirandabonomi opened 8 months ago

fmirandabonomi commented 8 months ago

When editing in VSCode a .qmd document with a fenced static code block which has the filename attribute and is situated inside a div with a #lst- label and lst-cap="..." caption, every time you type @ and request completion options, the pandoc process attending the request hangs and begins to consume all available memory until it is killed. After removing the offending filename attribute, autocompletion works again without issues.

I attach to this report a .qmd file displaying the issue (inside a .zip for compatibility with github). EDIT: There is a problem with the zip file (at least I can't download it) so I also reproduce the document at the end of this post

triggers_issue.zip

I'm using Quarto 1.3.549 with Visual Studio Code 1.76.2 and Quarto extension for VSCode v1.111.0, runing on MS Windows 11 Pro 10.0.22631. You can see the output of quarto check below.

> quarto check
Quarto 1.4.549
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.549
      Path: C:\Users\Fernando\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      Chromium: 869685
      TinyTeX: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.5
      Path: C:/Users/Fernando/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: 5.3.1
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.2.3
      Path: C:/PROGRA~1/R/R-42~1.3
      LibPaths:
        - C:/Program Files/R/R-4.2.3/library
      knitr: 1.42
      rmarkdown: 2.21

[>] Checking Knitr engine render......OK

Edit: there is a problem with the zip file so I also reproduce a document that triggers the issue

---
    title: Pandoc hangs when requesting completion
    lang: en
    author: fmirandabonomi
---

## The problem

When editing in VSCode a .qmd document with a fenced static code block which has the `filename` attribute and
is situated inside a div with a `#lst-` label and `lst-cap="..."` caption, every time you type `@` and request
completion options, the pandoc process attending the request hangs and begins to consume all available
memory until it is killed. It happens with this particular document due to the code block in @lst-triggers-issue.
When the pandoc process is terminates, Quarto CLI outputs the error in @lst-after-stopping-pandoc.
After removing the offending `filename` attribute, autocompletion works again without issues.

:::{#lst-triggers-issue lst-cap="This renders well, but pandoc goes boom when Quarto LSP enters a completion request"}
```{.c filename="hello_world.c"}
#include <stdio.h>
int main(void){
    printf("Hello world!\n");
    return 0;
}
```
:::

:::{#lst-after-stopping-pandoc lst-cap="This is the error I get after stopping pandoc"}
```{.default}
[Error - 7:07:51 PM] Request textDocument/completion failed.
  Message: Request textDocument/completion failed with message: Command failed: C:\Users\Fernando\AppData\Local\Programs\Quarto\bin\tools\pandoc --defaults defaults.yml
  Code: -32603 
```
:::