diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index 8be18ce144a..c2221a9d39e 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -535,6 +535,7 @@ function! s:completer_gls.init() dict abort " {{{2 if !has_key(b:vimtex.packages, 'glossaries-extra') | return | endif " Detect stuff like this: + " \GlsXtrLoadResources[src={glossary}] " \GlsXtrLoadResources[src=glossary.bib] " \GlsXtrLoadResources[src={glossary.bib}, selection={all}] " \GlsXtrLoadResources[selection={all},src={glossary.bib}] @@ -544,6 +545,7 @@ function! s:completer_gls.init() dict abort " {{{2 " ] let l:do_search = 0 + let b:vimtex.complete.glsbib = [] for l:line in vimtex#parser#preamble(b:vimtex.tex) if line =~# '^\s*\\GlsXtrLoadResources\s*\[' let l:do_search = 1 @@ -560,7 +562,13 @@ function! s:completer_gls.init() dict abort " {{{2 let l:value = trim(remove(l:matches, 0)) let l:value = substitute(l:value, '^{', '', '') let l:value = substitute(l:value, '[]}]\s*', '', 'g') - let b:vimtex.complete.glsbib = l:value + if !vimtex#paths#is_abs(l:value) + let l:value = vimtex#paths#join(b:vimtex.root, l:value) + endif + if !filereadable(l:value) + let l:value .= '.bib' + endif + call add(b:vimtex.complete.glsbib, l:value) break endif endwhile @@ -592,15 +600,24 @@ function! s:completer_gls.parse_glsentries() dict abort " {{{2 endfunction function! s:completer_gls.parse_glsbib() dict abort " {{{2 - let l:filename = get(b:vimtex.complete, 'glsbib', '') - if empty(l:filename) | return [] | endif - let l:candidates = [] - for l:entry in vimtex#parser#bib(l:filename, {'backend': 'vim'}) - call add(l:candidates, { - \ 'word': l:entry.key, - \ 'menu': get(l:entry, 'name', '--'), - \}) + + for l:filename in get(b:vimtex.complete, 'glsbib', []) + for l:entry in vimtex#parser#bib(l:filename, {'backend': 'vim'}) + let l:menu = '' + for l:c in ['name', 'long', 'title'] + if l:entry->has_key(l:c) + let l:menu = ' ' .. l:entry[l:c] + break + endif + endfor + + call add(l:candidates, { + \ 'word': l:entry.key, + \ 'kind': '[gls]', + \ 'menu': l:menu + \}) + endfor endfor return l:candidates diff --git a/test/test-completion-glossary/glossaries-extra-1.tex b/test/test-completion-glossary/glossaries-extra-1.tex index a3a22d95a79..4ce07190150 100644 --- a/test/test-completion-glossary/glossaries-extra-1.tex +++ b/test/test-completion-glossary/glossaries-extra-1.tex @@ -1,5 +1,4 @@ \documentclass{minimal} -\usepackage[german]{babel} \usepackage{csquotes} \usepackage[record,style=long]{glossaries-extra} @@ -7,6 +6,7 @@ src={glossaries-extra.bib}, selection={all}, ] +\GlsXtrLoadResources[src={glossary}] \begin{document} @@ -14,6 +14,8 @@ \gls{isbn} +\gls{API} + \printunsrtglossaries \end{document} diff --git a/test/test-completion-glossary/glossaries-extra.vim b/test/test-completion-glossary/glossaries-extra.vim index bc3de65f8ae..a28e47d0ab2 100644 --- a/test/test-completion-glossary/glossaries-extra.vim +++ b/test/test-completion-glossary/glossaries-extra.vim @@ -9,6 +9,6 @@ nnoremap q :qall! silent edit $TEXFILE let s:candidates = vimtex#test#completion('\gls{', '') -call assert_equal(len(s:candidates), 9) +call assert_equal(len(s:candidates), 10) call vimtex#test#finished() diff --git a/test/test-completion-glossary/glossary.bib b/test/test-completion-glossary/glossary.bib new file mode 100644 index 00000000000..273205fb8b0 --- /dev/null +++ b/test/test-completion-glossary/glossary.bib @@ -0,0 +1,7 @@ +@abbreviation{API, + title = {Application {{Programming Interface}}}, + long = {Application Programming Interface}, + prefix = {an\space}, + prefixfirst = {an\space}, + short = {API}, +}