micangl / cmp-vimtex

Vimtex source for nvim-cmp.
MIT License
78 stars 5 forks source link

Bug in bibtex parser #15

Closed lervag closed 7 months ago

lervag commented 8 months ago

Given the following lua init file e.g. under ~/test/test.lua:

local root = vim.fn.fnamemodify("./.lazy", ":p")

for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
    "hrsh7th/nvim-cmp",
    "micangl/cmp-vimtex",
    "lervag/vimtex",
}
require("lazy").setup(plugins, { root = root .. "/plugins" })

vim.g.vimtex_cache_root = "."
vim.g.vimtex_cache_persistent = false

vim.cmd([[silent! close]])
vim.cmd.edit("test.tex")

And the following test.tex:

\documentclass{article}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\begin{document}
Test \cite{gaonkar}
\end{document}

We get the following error message:

Error executing vim.schedule lua callback: .../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:64: attempt to index local 'entry' (a nil value)
stack traceback:
        .../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:64: in function 'format_entry'
        .../test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/parser.lua:143: in function 'callback'
        ...g/test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/timer.lua:72: in function <...g/test/.lazy/plugins/cmp-vimtex/lua/cmp_vimtex/timer.lua:66>
micangl commented 8 months ago

Thanks for raising the issue. Currently I'm in an exam session, so I won't have time to look into this for a while (until the end of february, most likely). I will, then, try to add some of your enhancements to the parser.

Unfortunately, I really have no time at the present moment.

lervag commented 8 months ago

No problem, do it when you have the time.

micangl commented 7 months ago

I have finally time to look into this. Would you mind posting the biblatex-examples.bib file included above?

lervag commented 7 months ago

biblatex-examples.bib is actually included with biblatex; i.e., you don't need the file, because you already have it. You can verify that with kpsewhich biblatex-examples.bib, which should output something like this:

> kpsewhich biblatex-examples.bib
/usr/share/texmf-dist/bibtex/bib/biblatex/biblatex/biblatex-examples.bib
micangl commented 7 months ago

I should have fixed it with the last commit.

The bug was related to the issue I raised for vimtex about a month ago: I was overwriting the native label and key bibtex fields.

lervag commented 7 months ago

Great, thanks!