From fc967983507ca0b162b9d6c13552787a4a03eb75 Mon Sep 17 00:00:00 2001 From: James Yu Date: Mon, 13 Jan 2025 14:21:00 +0800 Subject: [PATCH] Resolve #4502 Handle ids biblatex field --- src/completion/completer/citation.ts | 18 +++++++++++++++++- .../14_completion_citation/bibfile.bib | 6 ++++-- test/units/14_completion_citation.test.ts | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/completion/completer/citation.ts b/src/completion/completer/citation.ts index c53e19a15..39e2b1ec2 100644 --- a/src/completion/completer/citation.ts +++ b/src/completion/completer/citation.ts @@ -100,7 +100,23 @@ function provide(uri: vscode.Uri, line: string, position: vscode.Position): Comp const label = configuration.get('intellisense.citation.label') as string const fields = readCitationFormat(configuration) const range: vscode.Range | undefined = computeFilteringRange(line, position) - return updateAll(lw.cache.getIncludedBib(lw.root.file.path)).map(item => { + + const items = updateAll(lw.cache.getIncludedBib(lw.root.file.path)) + const alts: CitationItem[] = [] + items.forEach(item => { + if (item.fields.has('ids')) { + const ids = item.fields.get('ids')?.split(',').map(id => id.trim()) + if (ids === undefined || ids.length === 0) { + return + } + for (const id of ids) { + const alt = Object.assign({}, item) + alt.key = id + alts.push(alt) + } + } + }) + return [...items, ...alts].map(item => { // Compile the completion item label switch(label) { case 'bibtex key': diff --git a/test/fixtures/unittest/14_completion_citation/bibfile.bib b/test/fixtures/unittest/14_completion_citation/bibfile.bib index 4a30a18c9..69ecd8553 100644 --- a/test/fixtures/unittest/14_completion_citation/bibfile.bib +++ b/test/fixtures/unittest/14_completion_citation/bibfile.bib @@ -7,7 +7,8 @@ @article{miller2024 pages = {345--360}, year = {2024}, publisher = {Elsevier}, - doi = {10.1016/j.jac.2024.01.012} + doi = {10.1016/j.jac.2024.01.012}, + ids = {altid1} } @string{string1 = "Proceedings of the "} @@ -23,5 +24,6 @@ @article{miller2025 pages = {345--360}, year = {2025}, publisher = {Elsevier}, - doi = {10.1016/j.jac.2025.01.012} + doi = {10.1016/j.jac.2025.01.012}, + ids = {altid2, altid3} } \ No newline at end of file diff --git a/test/units/14_completion_citation.test.ts b/test/units/14_completion_citation.test.ts index 113163e3a..7556ff58d 100644 --- a/test/units/14_completion_citation.test.ts +++ b/test/units/14_completion_citation.test.ts @@ -92,5 +92,24 @@ describe(path.basename(__filename).split('.')[0] + ':', () => { assert.ok(suggestion) assert.strictEqual(suggestion.fields.author, 'Jane Miller and Robert Smith') }) + + it('should handle biblatex ids field', async () => { + await citation.parseBibFile(bibPath) + + const suggestions = provider.from([''], { uri: vscode.Uri.file(texPath), langId: 'latex', line: '', position: new vscode.Position(0, 0) }) + + assert.ok(suggestions.find(s => s.label === 'miller2024')) + assert.ok(suggestions.find(s => s.label === 'altid1')) + }) + + it('should handle biblatex ids field with multiple alt names', async () => { + await citation.parseBibFile(bibPath) + + const suggestions = provider.from([''], { uri: vscode.Uri.file(texPath), langId: 'latex', line: '', position: new vscode.Position(0, 0) }) + + assert.ok(suggestions.find(s => s.label === 'miller2025')) + assert.ok(suggestions.find(s => s.label === 'altid2')) + assert.ok(suggestions.find(s => s.label === 'altid3')) + }) }) })