James-Yu / LaTeX-Workshop

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

Unable to parse BibTeX files where citations use nested `@string`s #4021

Closed 0xabu closed 1 year ago

0xabu commented 1 year ago

Pre-checks*

Environment*

The Issue*

The following BibTeX file fails to parse, such that no entries appear in the citation browser / intellisense:

@string{string1 = "Proceedings of the "}
@string{string2 = string1 # "Foo"}

@inproceedings{testbib1,
  author    = {Author},
  title     = {Title},
  booktitle = string1,
  year      = {2023},
}

@inproceedings{testbib2,
  author    = {Author},
  title     = {Title},
  booktitle = string2,
  year      = {2023},
}

If I remove the entry named testbib2 (that uses the string with a nested expansion) then the file parses successfully and testbib1 now appears in the citation browser. Note that it's apparently ok if the nested string is still defined (it's not necessary to remove string2), however if any entry uses a nested string, then none of the entries from the file are usable.

Expected Behavior

Logs

Developer Tools Console

Parsing the file as described above:

[11:04:34.225][Extension] onDidSaveTextDocument triggered: file://%WS1%/refs2.bib
[11:04:34.244][Structure][BibTeX] Parse active BibTeX document for AST.
[11:04:34.245][Structure][BibTeX] Parsed 4 AST items.
[11:04:34.306][Cacher][Watcher] "change" emitted on %WS1%/refs2.bib .
[11:04:34.306][Intelli][Citation] Parsing .bib entries from %WS1%/refs2.bib
[11:04:34.307][Intelli][Citation] Parse BibTeX AST from %WS1%/refs2.bib .
[11:04:34.307][Event] FILE_CHANGED: "%WS1%/refs2.bib"

After removing testbib2 and saving the file:

[11:06:11.146][Extension] onDidSaveTextDocument triggered: file://%WS1%/refs2.bib
[11:06:11.243][Cacher][Watcher] "change" emitted on %WS1%/refs2.bib .
[11:06:11.243][Intelli][Citation] Parsing .bib entries from %WS1%/refs2.bib
[11:06:11.243][Intelli][Citation] Parse BibTeX AST from %WS1%/refs2.bib .
[11:06:11.244][Event] FILE_CHANGED: "%WS1%/refs2.bib"
[11:06:11.245][Intelli][Citation] Parsed 1 bib entries from %WS1%/refs2.bib .
[11:06:11.245][Structure][BibTeX] Parse active BibTeX document for AST.
[11:06:11.245][Event] FILE_PARSED: "%WS1%/refs2.bib"
[11:06:11.245][Structure][BibTeX] Parsed 3 AST items.
[11:06:11.246][Structure] Structure force updated with 1 entries for %WS1%/refs2.bib .
[11:06:11.246][Event] STRUCTURE_UPDATED
0xabu commented 1 year ago

Thanks for the quick fix!