diff --git a/src/completion/completer/glossary.ts b/src/completion/completer/glossary.ts index 09b1807ae..1624b3e5f 100644 --- a/src/completion/completer/glossary.ts +++ b/src/completion/completer/glossary.ts @@ -12,7 +12,8 @@ const logger = lw.log('Intelli', 'Glossary') export const provider: CompletionProvider = { from } export const glossary = { parse, - getItem + getItem, + parseBibFile } const data = { diff --git a/test/fixtures/armory/intellisense/glossary.bib b/test/fixtures/armory/intellisense/glossary.bib new file mode 100644 index 000000000..90320755d --- /dev/null +++ b/test/fixtures/armory/intellisense/glossary.bib @@ -0,0 +1,35 @@ +@symbol{fs, + name = {\ensuremath{f_s}}, + description = {sample rate} +} + +@symbol{theta, + name = {\ensuremath{\theta}}, + description = {horizontal angle} +} + +@entry{caesar, + name={\sortname{Gaius Julius}{Caesar}}, + first={\sortname{Julius}{Caesar}}, + text={Caesar}, + description={Roman politician and general}, + born={13~July 100 BC}, + died={15~March 44 BC}, + identifier={person} +} + +@entry{wellesley, + name={\sortname{Arthur}{Wellesley}}, + text={Wellington}, + description={Anglo-Irish soldier and statesman}, + born={1~May 1769 AD}, + died={14~September 1852 AD}, + othername={1st Duke of Wellington}, + identifier={person} +} + +@index{wellington, + name={Wellington}, + alias={wellesley}, + identifier={person} +} diff --git a/test/fixtures/armory/intellisense/glossary_bib.tex b/test/fixtures/armory/intellisense/glossary_bib.tex new file mode 100644 index 000000000..b33d56873 --- /dev/null +++ b/test/fixtures/armory/intellisense/glossary_bib.tex @@ -0,0 +1,9 @@ +\documentclass{article} +\usepackage{glossaries-extra} +\GlsXtrLoadResources[ + src={glos.bib}, +] + +\begin{document} +abc\gls{} +\end{document} diff --git a/test/fixtures/unittest/22_completion_glossary/glossary.bib b/test/fixtures/unittest/22_completion_glossary/glossary.bib new file mode 100644 index 000000000..90320755d --- /dev/null +++ b/test/fixtures/unittest/22_completion_glossary/glossary.bib @@ -0,0 +1,35 @@ +@symbol{fs, + name = {\ensuremath{f_s}}, + description = {sample rate} +} + +@symbol{theta, + name = {\ensuremath{\theta}}, + description = {horizontal angle} +} + +@entry{caesar, + name={\sortname{Gaius Julius}{Caesar}}, + first={\sortname{Julius}{Caesar}}, + text={Caesar}, + description={Roman politician and general}, + born={13~July 100 BC}, + died={15~March 44 BC}, + identifier={person} +} + +@entry{wellesley, + name={\sortname{Arthur}{Wellesley}}, + text={Wellington}, + description={Anglo-Irish soldier and statesman}, + born={1~May 1769 AD}, + died={14~September 1852 AD}, + othername={1st Duke of Wellington}, + identifier={person} +} + +@index{wellington, + name={Wellington}, + alias={wellesley}, + identifier={person} +} diff --git a/test/suites/04_intellisense.test.ts b/test/suites/04_intellisense.test.ts index 7de6815f4..fe1825278 100644 --- a/test/suites/04_intellisense.test.ts +++ b/test/suites/04_intellisense.test.ts @@ -6,7 +6,7 @@ import * as test from './utils' import { EnvSnippetType } from '../../src/types' import { isTriggerSuggestNeeded } from '../../src/completion/completer/macro' -suite.skip('Intellisense test suite', () => { +suite('Intellisense test suite', () => { test.suite.name = path.basename(__filename).replace('.test.js', '') test.suite.fixture = 'testground' @@ -420,6 +420,20 @@ suite.skip('Intellisense test suite', () => { assert.ok(suggestions.items.find(item => item.label === 'abbr_x' && item.detail === 'A first abbreviation')) }) + test.run('glossary intellisense from .bib files', async (fixture: string) => { + await test.load(fixture, [ + {src: 'intellisense/glossary_bib.tex', dst: 'main.tex'}, + {src: 'intellisense/glossary.bib', dst: 'glos.bib'} + ]) + const suggestions = test.suggest(7, 8) + assert.strictEqual(suggestions.items.length, 5) + assert.ok(suggestions.items.find(item => item.label === 'fs' && item.detail?.includes('\\ensuremath{f_s}'))) + assert.ok(suggestions.items.find(item => item.label === 'theta' && item.detail?.includes('\\ensuremath{\theta}'))) + assert.ok(suggestions.items.find(item => item.label === 'caesar' && item.detail?.includes('\\sortname{Gaius Julius}{Caesar}'))) + assert.ok(suggestions.items.find(item => item.label === 'wellesley' && item.detail?.includes('\\sortname{Arthur}{Wellesley}'))) + assert.ok(suggestions.items.find(item => item.label === 'wellington' && item.detail?.includes('Wellington'))) + }) + test.run('@-snippet intellisense and configs intellisense.atSuggestion*', async (fixture: string) => { const replaces = {'@+': '\\sum', '@8': '', '@M': '\\sum'} await vscode.workspace.getConfiguration('latex-workshop').update('intellisense.atSuggestion.user', replaces) diff --git a/test/units/22_completion_glossary.test.ts b/test/units/22_completion_glossary.test.ts index bfe6bf3cf..288d36d7d 100644 --- a/test/units/22_completion_glossary.test.ts +++ b/test/units/22_completion_glossary.test.ts @@ -3,7 +3,7 @@ import * as path from 'path' import * as sinon from 'sinon' import { lw } from '../../src/lw' import { assert, get, mock, set } from './utils' -import { provider } from '../../src/completion/completer/glossary' +import { glossary, provider } from '../../src/completion/completer/glossary' describe(path.basename(__filename).split('.')[0] + ':', () => { const fixture = path.basename(__filename).split('.')[0] @@ -24,16 +24,16 @@ describe(path.basename(__filename).split('.')[0] + ':', () => { sinon.restore() }) - describe('lw.completion->glossary', () => { - function getSuggestions() { - return provider.from(['', ''], { - uri: vscode.Uri.file(texPath), - langId: 'latex', - line: '', - position: new vscode.Position(0, 0), - }) - } + function getSuggestions() { + return provider.from(['', ''], { + uri: vscode.Uri.file(texPath), + langId: 'latex', + line: '', + position: new vscode.Position(0, 0), + }) + } + describe('lw.completion->glossary', () => { it('should parse and provide \\newacronym definition', async () => { readStub.resolves('\\newacronym{rf}{RF}{radio-frequency}') await lw.cache.refreshCache(texPath) @@ -107,4 +107,24 @@ describe(path.basename(__filename).split('.')[0] + ':', () => { assert.strictEqual(suggestions.find(s => s.label === 'rf')?.detail, 'radio-frequency') }) }) + + describe('lw.completion->glossary.parseBibFile', () => { + const bibFile = 'glossary.bib' + const bibPath = get.path(fixture, bibFile) + + it('should parse the bib file', async () => { + readStub.withArgs(texPath).resolves(`\\GlsXtrLoadResources[src={${bibFile}}]`) + await lw.cache.refreshCache(texPath) + sinon.restore() + + await glossary.parseBibFile(bibPath) + + const suggestions = getSuggestions() + assert.ok(suggestions.find(item => item.label === 'fs' && item.detail?.includes('\\ensuremath{f_s}'))) + assert.ok(suggestions.find(item => item.label === 'theta' && item.detail?.includes('\\ensuremath{\\theta}'))) + assert.ok(suggestions.find(item => item.label === 'caesar' && item.detail?.includes('\\sortname{Gaius Julius}{Caesar}'))) + assert.ok(suggestions.find(item => item.label === 'wellesley' && item.detail?.includes('\\sortname{Arthur}{Wellesley}'))) + assert.ok(suggestions.find(item => item.label === 'wellington' && item.detail?.includes('Wellington'))) + }) + }) })