James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.66k stars 530 forks source link

`Error loading AST during structuring` when meeting `$\in [1, 2)$` #3751

Closed Discreater closed 1 year ago

Discreater commented 1 year ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The issue has not been reported in this repository.
  • [x] The issue remains after disabling all other extensions and restarting Visual Studio Code.
  • [x] The FAQ cannot address the issue.
  • [x] The issue is not related to compiling a document, or the document can be successfully compiled in the OS terminal but not in Visual Studio Code with this extension.

Environment*

Please write exact version numbers instead of descriptors such as latest.

  • Operating System: [WSL (Arch with kernel: 5.15.79.1-microsoft-standard-WSL2) in Windows 11 2262.1265]
  • Visual Studio Code Version: [1.75.1]
  • LaTeX Workshop Version: [9.7.0]
  • TeX Distribution Version: [TeX Live 2022.62885-5]

Please list the environment and version number if you are using VSCodium, Snap or Flatpack versions of Visual Studio Code, and/or Visual Studio Code Remote Containers/SSH/WSL.

  • I am using WSL extension whose version is 0.75.3

The Issue*

Please briefly describe the issue you come across.

  • When thier are math expressions which have unclosed square bracket after \in like $\in [1, 2)$, the latex-workshop will log an error: Error loading AST during structuring: %WS1%/base.tex. And the structure list in the left side is empty. However, the pdf can generate successfully.

Reproduction Steps

Please list out the steps to reproduce your bug. Include relevant environmental variables or any other configuration. Below is the tex.


\documentclass{article}

\begin{document}

\section{Section 1}

$\in [1, 2)$

\section{Section 2} \end{document}


### Expected Behavior
> _What were you expecting to see? Include any relevant examples or documentation links._
- Structure should show normally.

## Logs
### LaTeX Workshop Output*
> _Please paste the whole log messages below, not parts of ones. The log should start with `New log placeholder %WS1% registered`._

[17:15:52][Logger] New log placeholder %WS1% registered for /home/alkaid/temp/ltw-t . [17:15:52][Config] Configuration for workspace: file://%WS1% . [17:15:52][Config] editor.acceptSuggestionOnEnter: "on" . [17:15:52][Config] latex-workshop.bind.enter.key: true . [17:15:52][Config] latex-workshop.docker.enabled: false . [17:15:52][Config] latex-workshop.docker.image.latex: "" . [17:15:52][Config] latex-workshop.hover.preview.mathjax.extensions: [] . [17:15:52][Config] latex-workshop.intellisense.package.enabled: true . [17:15:52][Config] latex-workshop.intellisense.update.aggressive.enabled: false . [17:15:52][Config] latex-workshop.intellisense.update.delay: 1000 . [17:15:52][Config] latex-workshop.latex.autoBuild.run: "onFileChange" . [17:15:52][Config] latex-workshop.latex.build.forceRecipeUsage: true . [17:15:52][Config] latex-workshop.latex.outDir: "%DIR%" . [17:15:52][Config] latex-workshop.latex.recipes: [ { "name": "latexmk", "tools": [ "latexmk" ] }, { "name": "latexmk (latexmkrc)", "tools": [ "latexmk_rconly" ] }, { "name": "latexmk (lualatex)", "tools": [ "lualatexmk" ] }, { "name": "latexmk (xelatex)", "tools": [ "xelatexmk" ] }, { "name": "pdflatex -> bibtex -> pdflatex * 2", "tools": [ "pdflatex", "bibtex", "pdflatex", "pdflatex" ] }, { "name": "Compile Rnw files", "tools": [ "rnw2tex", "latexmk" ] }, { "name": "Compile Jnw files", "tools": [ "jnw2tex", "latexmk" ] }, { "name": "Compile Pnw files", "tools": [ "pnw2tex", "latexmk" ] }, { "name": "tectonic", "tools": [ "tectonic" ] } ] . [17:15:52][Config] latex-workshop.latex.tools: [ { "name": "latexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "-outdir=%OUTDIR%", "%DOC%" ], "env": {} }, { "name": "lualatexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-lualatex", "-outdir=%OUTDIR%", "%DOC%" ], "env": {} }, { "name": "xelatexmk", "command": "latexmk", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-xelatex", "-outdir=%OUTDIR%", "%DOC%" ], "env": {} }, { "name": "latexmk_rconly", "command": "latexmk", "args": [ "%DOC%" ], "env": {} }, { "name": "pdflatex", "command": "pdflatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOC%" ], "env": {} }, { "name": "bibtex", "command": "bibtex", "args": [ "%DOCFILE%" ], "env": {} }, { "name": "rnw2tex", "command": "Rscript", "args": [ "-e", "knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')" ], "env": {} }, { "name": "jnw2tex", "command": "julia", "args": [ "-e", "using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")" ], "env": {} }, { "name": "jnw2texminted", "command": "julia", "args": [ "-e", "using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")" ], "env": {} }, { "name": "pnw2tex", "command": "pweave", "args": [ "-f", "tex", "%DOC_EXT%" ], "env": {} }, { "name": "pnw2texminted", "command": "pweave", "args": [ "-f", "texminted", "%DOC_EXT%" ], "env": {} }, { "name": "tectonic", "command": "tectonic", "args": [ "--synctex", "--keep-logs", "%DOC%.tex" ], "env": {} } ] . [17:15:52][Config] latex-workshop.viewer.pdf.internal.keyboardEvent: "auto" . [17:15:52][Manager] Set $LATEXWORKSHOP_DOCKER_LATEX: "" [17:15:52][Server] Creating LaTeX Workshop http and websocket server. [17:15:52][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":33705} . [17:15:52][Server] valdOrigin is http://127.0.0.1:33705 [17:15:52][Extension] Initializing LaTeX Workshop. [17:15:52][Extension] Extension root: /home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0 [17:15:52][Extension] $PATH: /home/alkaid/.vscode-server/bin/441438abd1ac652551dbe4d408dfcec8a499b8bf/bin/remote-cli:/home/alkaid/.local/share/pnpm:/run/user/1000/fnm_multishells/972_1677652613665/bin:/home/alkaid/arm-gnu/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/:/opt/pmon2000/tools/bin/:/home/alkaid/nscscc/chiplab/toolchains/loongarch32r-linux-gnusf-2022-05-20/bin/:/home/alkaid/.cargo/bin:/home/alkaid/program/bin:/home/alkaid/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl [17:15:52][Extension] $SHELL: /usr/bin/zsh [17:15:52][Extension] $LANG: en_US.UTF-8 [17:15:52][Extension] $LC_ALL: undefined [17:15:52][Extension] process.platform: linux [17:15:52][Extension] process.arch: x64 [17:15:52][Extension] vscode.env.appName: Visual Studio Code [17:15:52][Extension] vscode.env.remoteName: wsl [17:15:52][Extension] vscode.env.uiKind: 1 [17:15:52][Extension] LaTeX Workshop initialized. [17:15:52][Format][Bib] Bibtex format config: {"tab":" ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]} [17:15:52][Extension] Trigger characters for intellisense of LaTeX documents: ["\",",","{"] [17:15:52][Manager] Current workspace folders: ["file://%WS1%"] [17:15:52][Manager] Found root file from active editor: %WS1%/base.tex [17:15:52][Manager] Root file changed: from undefined to %WS1%/base.tex [17:15:52][Manager] Start to find all dependencies. [17:15:52][Manager] Root file languageId: latex [17:15:52][Cacher][Watcher] Reset. [17:15:52][Cacher] Adding %WS1%/base.tex . [17:15:52][Cacher][Watcher] Watched %WS1%/base.tex with a new watcher on %WS1% . [17:15:52][Cacher] Caching %WS1%/base.tex . [17:15:52][Cacher] Updated inputs of %WS1%/base.tex . [17:15:52][Cacher] Use RegExp to update elements of %WS1%/base.tex . [17:15:52][DupLabel] Checking for duplicate labels: %WS1%/base.tex . [17:15:52][Cacher] Updated elements of %WS1%/base.tex . [17:15:52][Cacher] Updated bibs of %WS1%/base.tex . [17:15:52][Cacher] Cached %WS1%/base.tex . [17:15:52][Structure] Error loading AST during structuring: %WS1%/base.tex . [17:15:52][Structure] Structure force updated with 0 root sections for %WS1%/base.tex . [17:15:52][Cacher] Parsing .fls %WS1%/base.fls . [17:15:52][Cacher] Found .aux %WS1%/base.tex from .fls %WS1%/base.fls , parsing. [17:15:52][Cacher] Parsed .aux %WS1%/base.tex . [17:15:52][Cacher] Parsed .fls %WS1%/base.fls . [17:15:52][Structure] Structure updated with 0 root sections for %WS1%/base.tex . [17:15:52][Viewer][Panel] Restoring at column 1 with state {"pdfFileUri":"file://%WS1%/base.pdf","scale":"auto","scrollMode":0,"sidebarView":0,"spreadMode":0,"scrollTop":0,"scrollLeft":0,"trim":0,"synctexEnabled":true,"autoReloadEnabled":true}. [17:15:52][Viewer][Panel] Internal PDF viewer at http://127.0.0.1:33705/viewer.html?file=pdf..ZmlsZSUzQSUyRiUyRiUyRmhvbWUlMkZhbGthaWQlMkZ0ZW1wJTJGbHR3LXQlMkZiYXNlLnBkZg . [17:15:52][Cacher][Watcher] Watched %WS1%/base.pdf with a new watcher on %WS1% . [17:15:53][Viewer] Handle data type: open [17:15:54][Server] Preview PDF file: file://%WS1%/base.pdf [17:15:54][Viewer] Handle data type: loaded [17:15:55][Structure] Error loading AST during structuring: %WS1%/base.tex .


### Developer Tools Console
> _Please paste the whole log messages below, not parts of ones. This console logs can sometimes be very important in many cases. To access the log, click `Help` -> `Toggle Developer Tools` -> `Console`._

WARN Via 'product.json#extensionEnabledApiProposals' extension 'github.vscode-pull-request-github' wants API proposal 'commentsResolvedState' but that proposal DOES NOT EXIST. Likely, the proposal has been finalized (check 'vscode.d.ts') or was abandoned. log.ts:392 INFO Invoking resolveAuthority(wsl)... log.ts:392 INFO [LocalProcess0][resolveAuthority(wsl,1)][0ms] obtaining proxy... log.ts:392 INFO [LocalProcess0][resolveAuthority(wsl,1)][0ms] invoking... log.ts:392 INFO [LocalProcess0][resolveAuthority(wsl,1)][269ms] returned 127.0.0.1:7098 log.ts:392 INFO resolveAuthority(wsl) returned '127.0.0.1:7098' after 269 ms log.ts:392 INFO Creating a socket (renderer-Management-41d50be6-7c61-4eae-9806-e57a6d58d59a)... log.ts:392 INFO Creating a socket (renderer-ExtensionHost-e543cc3c-c84a-40e2-a108-7b19ba05db49)... log.ts:392 INFO Creating a socket (renderer-Management-41d50be6-7c61-4eae-9806-e57a6d58d59a) was successful after 69 ms. log.ts:392 INFO Creating a socket (renderer-ExtensionHost-e543cc3c-c84a-40e2-a108-7b19ba05db49) was successful after 174 ms. TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex. Old grammar file: file:///c%3A/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json. New grammar file: vscode-remote://wsl%2Barch/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/syntax/TeX.tmLanguage.json register @ TMScopeRegistry.ts:47 TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex.latex. Old grammar file: file:///c%3A/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json. New grammar file: vscode-remote://wsl%2Barch/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/syntax/LaTeX.tmLanguage.json register @ TMScopeRegistry.ts:47 TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.bibtex. Old grammar file: file:///c%3A/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json. New grammar file: vscode-remote://wsl%2Barch/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/syntax/Bibtex.tmLanguage.json register @ TMScopeRegistry.ts:47 TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined. Old grammar file: file:///c%3A/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json. New grammar file: vscode-remote://wsl%2Barch/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/syntax/markdown-latex-combined.tmLanguage.json register @ TMScopeRegistry.ts:47 TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex. Old grammar file: file:///c%3A/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json. New grammar file: vscode-remote://wsl%2Barch/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/syntax/cpp-grammar-bailout.tmLanguage.json register @ TMScopeRegistry.ts:47 log.ts:404 ERR Cannot get default system shell when there is no backend for remote authority 'wsl+arch': Error: Cannot get default system shell when there is no backend for remote authority 'wsl+arch' at Object.getDefaultSystemShell (vscode-file://vscode-app/c:/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1704:6413) at async i.v (vscode-file://vscode-app/c:/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1697:18560) at async i.r (vscode-file://vscode-app/c:/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1697:17823) at async i.getDefaultProfile (vscode-file://vscode-app/c:/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1697:17154) at async Promise.all (index 0) at async r.y (vscode-file://vscode-app/c:/Users/qtq/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1696:50610) viewer.js:13222 #bookmark1 is undefined. translateElement @ viewer.js:13222 log.ts:392 INFO [perf] Render performance baseline is 15ms DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/latexworkshop.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/connection.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/htmleditor.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/synctex.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/pagetrimmer.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/externalpromise.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/viewerhistory.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/build/pdf.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/out/viewer/components/utils.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/viewer/viewer.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE DevTools failed to load source map: Could not parse content for vscode-webview://06mfgp1vrh5kpemudd7huesfo3g88hh9thrb9pl3i34u0085tdah/pdf.worker.js.map: Unexpected end of JSON input DevTools failed to load source map: Could not load content for http://127.0.0.1:33705/build/pdf.worker.js.map: Fetch through target failed: Target not supported; Fallback: Unknown error DevTools failed to load source map: Could not load content for https://vscode-remote+wsl-002barch.vscode-resource.vscode-cdn.net/home/alkaid/.vscode-server/extensions/james-yu.latex-workshop-9.7.0/node_modules/pdfjs-dist/build/pdf.js.map: Connection error: net::ERR_CONNECTION_CLOSED



## Anything Else?
> _Add any other context about the problem below._
- 
jlelong commented 1 year ago

The issue is related to intellisense.fastparse.enabled being set to true. Calling utils.stripText on the above example removes the leading $

\documentclass{article}

\begin{document}

\section{Section 1}

\in [ 1, 2)$

\section{Section 2}
\end{document}
jlelong commented 1 year ago

Actually, it does not fix the issue if the space is removed in \in [ 1, 2). So, the following code still breaks the structure provider

\documentclass{article}

\begin{document}

\section{Section 1}

$\in[ 1, 2)$

\section{Section 2}
\end{document}

I think that the real issue is with the function getLongestBalancedString, which returns the complete string when the starting bracket is not balanced. I am wondering if we could return undefined instead and handle this in the calling function. What do you think?

James-Yu commented 1 year ago

I think that the real issue is with the function getLongestBalancedString, which returns the complete string when the starting bracket is not balanced. I am wondering if we could return undefined instead and handle this in the calling function.

I agree. Such use cases were not considered originally. I will make the tweaks and create a PR shortly.

Though unable to solve this issue, I think 4172680545272593cdeab3919e508cf5106f60db is still correct to some extent, as spaces should not appear between command name and its first argument. Let's just leave the commit here?

jlelong commented 1 year ago

Though unable to solve this issue, I think 4172680 is still correct to some extent, as spaces should not appear between command name and its first argument. Let's just leave the commit here?

I am not so sure. I agree that we tend not to add extra spaces between a command and its first argument but adding some spaces is accepted by the LaTeX compiler. The LaTeX code $\sqrt {x}$ produces the same output as $\sqrt{x}$.

James-Yu commented 1 year ago

Change reverted in 9114006