James-Yu / LaTeX-Workshop

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

Problems pane truncates filename for LaTeX warnings when path/filename contains opening parenthesis #4447

Closed scoennz closed 1 month ago

scoennz commented 1 month ago

Pre-checks

Environment

The Issue

When the path or the filename of a .tex file contains an opening parenthesis [ e.g. D:\Folder\test_(2024).tex ] , the Problems pane fails to provide the correct link to the file for Warnings. The path/filename is truncated just before the opening parenthesis, resulting in an incorrect filename to link to. Interestingly, at the same time, for the same file, Errors are correctly linked. See screen capture of example Problems pane below.

Closing parentheses, by themselves, do not trigger the issue. E.g. D:\Folder\test_2024).tex works fine.

Changing the option latex-workshop.message.convertFilenameEncoding (true or false) does not solve the problem.

Reproduction Steps

  1. Create a .tex file whose filename or its path contains at least one opening parenthesis. E.g. D:\Folder_(2024)\test.tex or D:\Folder\test_(2024).tex
  2. Put some LaTeX code into that file and make sure that it triggers at least one warning, or one warning and one error. Below, I provide a MWE. The global document class options [a4] is unused (Warning) and the x=2 equation has a missing closing $ (Error).
    \documentclass[a4]{article}
    \begin{document}
        Text $x=2
    \end{document} 
  3. Build the project, open the Problems pane . Clicking on the Error brings up the right line in the .tex file. Clicking on the Warning fails. Displaying the Problems Pane as a List reveals that the Error points to test_(2024).tex (correct filename) while the Warnings points to test_ (incorrect, truncated filename or path). See below for a screenshot.

image

Expected Behavior

Filenames or paths with (opening) parentheses are valid on most OSs and are used by many. Problems pane links for Warnings and Errors should work equally well with such paths/filenames.

Logs

LaTeX Workshop Output

Latexmk: Sometimes, the -f option can be used to get latexmk
  to try to force complete processing.
  But normally, you will need to correct the file(s) that caused the
  error, and then rerun latexmk.
  In some cases, it is best to clean out generated files before rerunning
  latexmk after you've corrected the files.
Reverting Windows console CPs to (in,out) = (437,65001)
Initial Win CP for (console input, console output, system): (CP437, CP65001, CP1252)
I changed them all to CP1252
Rc files read:
  NONE
Latexmk: This is Latexmk, John Collins, 7 Apr. 2024. Version 4.85.
Latexmk: Nothing to do for 'd:/Folder/test_(2024).tex'.
Latexmk: All targets (test_(2024).pdf) are up-to-date
Collected error summary (may duplicate other messages):
  pdflatex: gave an error in previous invocation of latexmk.

Note: when the log is seen in the Output pane in VS Code, the filename in the line Latexmk: Nothing to do for 'd:/Folder/test_(2024).tex' is underlined up to and excluding the opening parenthesis (i.e. only d:/Folder/test_ is underlined in my example; not the rest). However, latexmk works fine and the documents is correctly built.

Developer Tools Console

log.ts:419  INFO Started local extension host with pid 19156.
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/TeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/LaTeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/Bibtex.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/markdown-latex-combined.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/TeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/LaTeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/Bibtex.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/markdown-latex-combined.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///c%3A/Users/xxxx/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///c%3A/Users/xxxx/.vscode/extensions/james-yu.latex-workshop-10.5.5/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
log.ts:419  INFO [perf] Render performance baseline is 38ms
notificationsAlerts.ts:42 Recipe terminated with error.
c @ notificationsAlerts.ts:42

Anything Else?

The problem persists whatever type of character is after/before the opening parenthesis (letter, digit, or whitespace). Note that I haven't tested the behavior when sub-files are called (included) in a main.tex file.

Thanks for looking into this, and thanks for the great extension.

James-Yu commented 1 month ago

Thanks for the issue. However, this is a limit of latex logging, which uses closing brace ) to denote the end of a file name when outputting file trace in log. Error messages contain the file path, so it will work. Warnings do not output file paths, so we need to infer from the file trace and breaks on closing brace in file path.