Skip to content

Commit

Permalink
Resolve #4502 Handle ids biblatex field
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Jan 13, 2025
1 parent 281505f commit fc96798
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/completion/completer/citation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/unittest/14_completion_citation/bibfile.bib
Original file line number Diff line number Diff line change
Expand Up @@ -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 "}
Expand All @@ -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}
}
19 changes: 19 additions & 0 deletions test/units/14_completion_citation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
})
})

0 comments on commit fc96798

Please sign in to comment.