quarto-dev/quarto-vscode

VS Code autocomplete for cross references not working

jpmorr opened this issue · 10 comments

I noticed that when working in VS code and I try to add a cross-reference the autocomplete fails and I get the following message in the VS code output terminal:

image

Not quite sure if this is an extension problem or a quarto cli problem.

Could you provide the content you are running over when this error occurs? (this isn't known to be a problem but there is likely something specific to your document or project that we aren't handling correctly)

It's a book project with quite a few sections. It's not quite finished yet so I don't have it on github or gitlab yet. Let me see if I can try to recreate the problem with a simple example first or if it's related to my document, then I can start uploading.

@jjallaire It's definitely something related to my book project as in a new book project created from the template with a few figures and equations added, the cross-referencing works fine.

So I think I need to try and debug this project to find the cause. Could it be caused by using multiple parts?

I don't think it has anything to do with the parts. If you can send me a link to the source I'd be happy to debug.

If you could also LMK the version of Quarto you are running I can do some more informed speculation about the cause. If you aren't able to share the source code then you should probably debug by progressively adding/removing chapters and sections until you narrow it down (but honestly if you can share the source it's miles easier for me to debug)

@jjallaire It was pretty easy to find the culprit because every file up to a certain chapter worked. In the first file that threw the output error I was able to figure out that it's caused by a code listing. Here the offending item:

#-----------------------#
#    Preference File    #
#-----------------------#

If I comment out that block, everything works fine in that chapter and all following ones.

book>quarto check

[>] Checking Quarto installation......OK
      Version: 1.1.163
      Path: C:\Users\jpmor\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

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

[>] Checking Python 3 installation....OK
      Version: 3.9.13 (Conda)
      Path: C:/Users/jpmor/anaconda3/python.exe
      Jupyter: 4.11.1
      Kernels: julia-1.4, julia-1.6, julia-1.7, juliapro_v1.5.4-1-1.5, pycharm-20203b08, python3, iota

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

[>] Checking R installation...........OK
      Version: 4.1.3
      Path: C:/PROGRA~1/R/R-41~1.3
      LibPaths:
        - C:/Users/jpmor/OneDrive/Documents/R/win-library/4.1
        - C:/Program Files/R/R-4.1.3/library
      rmarkdown: 2.14

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

I'm using v1.37 of the VS code extension.

Could you give me a bit more in terms of what is actually required to reproduce this? I tried the following and there were no issues:

# Introduction

```{#lst-foobar}
#-----------------------#
#    Preference File    #
#-----------------------#
```

If could give me a complete minimal example of the input that fails that will save us some time.

@jjallaire Here's an example that is enough to break VS code autocompletion for me.

Create a new book project.

add the following content to intro.qmd:

# Introduction

This is a book created from markdown and executable code.

See @knuth84 for additional discussion of literate programming.

Example $x$ and $x^2 + x + 1$.

$$
k_1 = \dfrac{E_b A_b}{L_b}
$$ {#eq-k1}

@eq-k1

$$
\left[ K \right] =
\begin{bmatrix} k_1 & \cdot & \cdot & \cdot & \cdot & \cdot & -k_1 & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & k_2 & \cdot & \cdot & \cdot & k_3 & \cdot & -k_2 & \cdot & \cdot & \cdot & k_3 \\
\cdot & \cdot & k_2 & \cdot & -k_3 & \cdot & \cdot & \cdot & -k_2 & \cdot & -k_3 & \cdot \\
\cdot & \cdot & \cdot & k_4 & \cdot & \cdot & \cdot & \cdot & \cdot & -k_4 & \cdot & \cdot \\
\cdot & \cdot & -k_3 & \cdot & k_5 & \cdot & \cdot & \cdot & k_3 & \cdot & k_6 & \cdot \\
\cdot & k_3 & \cdot & \cdot & \cdot & k_5 & \cdot & -k_3 & \cdot & \cdot & \cdot & k_6 \\
-k_1 & \cdot & \cdot & \cdot & \cdot & \cdot & k_1 & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & -k_2 & \cdot & \cdot & \cdot & k_3 & \cdot & k_2 & \cdot & \cdot & \cdot & -k_3 \\
\cdot & \cdot & -k_2 & \cdot & k_3 & \cdot & \cdot & \cdot & k_2 & \cdot & k_3 & \cdot \\
\cdot & \cdot & \cdot & -k_4 & \cdot & \cdot & \cdot & \cdot & \cdot & k_4 & \cdot & \cdot \\
\cdot & \cdot & -k_3 & \cdot & k_6 & \cdot & \cdot & \cdot & k_3 & \cdot & k_5 & \cdot \\
\cdot & k_3 & \cdot & \cdot & \cdot & k_6 & \cdot & -k_3 & \cdot & \cdot & \cdot & k_5 
\end{bmatrix}
$$ {#eq-StiffnessMatrix}


\```{#lst-prefs .python lst-cap="Sum Function" filename=sum.py}
def sum(a, b):
    sum = a + b
    print(f'Sum: {sum}`)
    return sum
\```

As can be seen from @lst-prefs it is absolutely pointless writing this function. 

I had to escape the nested code block with \ in the example. Once this is loaded into VS code I get the error as soon as I've typed @. If it doesn't break on your setup, then it must be specific to my computer.

@jjallaire I've just realised that the big equation probably wont render in pdf format without including the following \setcounter{MaxMatrixCols}{20} in the in-header.tex file due to some AMS default settings. Not sure if that will be important.

Thanks! This was an issue in quarto-cli fixed here: quarto-dev/quarto-cli@7938845

The fix is available in our v1.2 pre-release here: https://quarto.org/docs/download/prerelease.html