diff --git a/lua/cmp_vimtex/parser.lua b/lua/cmp_vimtex/parser.lua index 8ef09a0..9e40fe1 100644 --- a/lua/cmp_vimtex/parser.lua +++ b/lua/cmp_vimtex/parser.lua @@ -208,6 +208,19 @@ parser.parse_string = function(self, line) end parser.parse_entry = function(self, line) + -- The cite key is not required to share a line with "@type{" (this is how + -- OpenReview exports its BibTeX). When parse_type could not find it, pick + -- it up from the first subsequent line that supplies it. + if self.current.cite_key == nil then + local key = vim.fn['matchlist'](line, [[\v^\s*([^, ]+)\s*,\s*(.*)]]) + if self.empty(key) then + self.current.body = self.current.body .. line + return false + end + self.current.cite_key = key[2] + line = key[3] + end + self.current.level = self.current.level + vim.fn['cmp_vimtex#count'](line, '{') - vim.fn['cmp_vimtex#count'](line, '}') if self.current.level > 0 then self.current.body = self.current.body .. line @@ -329,6 +342,10 @@ parser.empty = function(list) return false end end + + -- nil (e.g. an out-of-range matchlist() result) counts as empty; without + -- this the guards above silently fall through on a nil argument. + return true end return parser