Skip to content

Fixes #1658 again#2035

Closed
TpmKranz wants to merge 4 commits intolervag:masterfrom
TpmKranz:fix-biblatex-glob
Closed

Fixes #1658 again#2035
TpmKranz wants to merge 4 commits intolervag:masterfrom
TpmKranz:fix-biblatex-glob

Conversation

@TpmKranz
Copy link
Copy Markdown
Contributor

@TpmKranz TpmKranz commented Apr 19, 2021

The fix in 2efe806 isn't used if BibLaTeX is detected, even though globbing is only possible with BibLaTeX's biber.

Since b7fbff1, that code path is only used if there aren't better methods of detecting bib files. That was okay because the only other method introduced was to parse BibTeX's blg file and BibTeX can't handle globbing anyway. But in 2536f04, support for biber's bcf file was added without also adding globbing support.

Apparently, globbing can be disabled per resource, so filenames that are candidates for globbing must be retained in the file list. This should only have an effect with curly braces, though. Globbing candidates that aren't actual filenames will be filtered out with s:validate(), as before.

See also: #1658

Copy link
Copy Markdown
Owner

@lervag lervag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This does seem pretty useful. It would be nice to have a simple example to test this. Perhaps we could even make a test?

Copy link
Copy Markdown
Owner

@lervag lervag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #2037:

The test used to always take the second path because vimtex doesn't know about the biblatex package being loaded before a compile.

Ah, yes: there are now three branches in the #files() function: 1) the "biblatex + bcf" branch, 2) the "blg" branch, and 3) the manual branch. And the old code only checks the third.

However, I propose, instead of doing the compilation every time, we simply add a bcf file to the test assets. Then we can simplify everything quite a lot. I.e., we can have test_globbed.bcf with only a single line:

<bcf:datasource type="file" datatype="bibtex" glob="false">test_gl*.bib</bcf:datasource>

Of course, this will force the first branch to execute, and then the third one is not tested. So, to test both the old and new branches, it might be necessary, or at least simpler, to make two test files.

The following seems to work quite well:

set nocompatible
let &rtp = '../..,' . &rtp
filetype plugin on

nnoremap q :qall!<cr>

let g:vimtex_cache_root = '.'
let g:vimtex_cache_persistent = 0

silent edit test_globbed_manual.tex

if empty($INMAKE) | finish | endif

let s:candidates = vimtex#test#completion('\cite{', '')
call vimtex#test#assert_equal(1, len(s:candidates))

bwipeout!
silent edit test_globbed_bcf.tex

let s:candidates = vimtex#test#completion('\cite{', '')
call vimtex#test#assert_equal(2, len(s:candidates))

quit!
% test_globbed_manual.tex
\documentclass{article}
\addbibresource{test_gl*manual.bib}
\begin{document}
Test
\end{document}
% test_globbed_bcf.tex
\documentclass{article}
\usepackage{biblatex}
\addbibresource{test_gl*bcf.bib}
\begin{document}
Test
\end{document}

And where the *manual.bib has one key and *bcf.bib has two keys. What do you think?

@TpmKranz TpmKranz force-pushed the fix-biblatex-glob branch 2 times, most recently from 8540bea to 1e7c67c Compare April 25, 2021 17:30
@TpmKranz
Copy link
Copy Markdown
Contributor Author

This now relies on vimtex not throwing out duplicate bibliography keys. If this ever changes, one would need to replace the symlinks with proper bib files. Copies of the original with slightly different citation keys should be enough. Of course that would open the possibility for your idea of different numbers of keys per file, maybe powers of two so one can easily see from the assertion failure message which files weren't found.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Apr 25, 2021

Thanks! FYI, this does not pass tests for me. In particular, the manual route does not pass, and it seems to be something with the caches. Perhaps there's a bug in the cache mechanism, but I'm curious, why is not my much simpler version of the tests sufficient here?

@TpmKranz
Copy link
Copy Markdown
Contributor Author

TpmKranz commented Apr 26, 2021

FYI, this does not pass tests for me. In particular, the manual route does not pass, and it seems to be something with the caches.

This seems to be a flakey test. Before I pushed, the test was failing for me on top of v2.4 and passing on top of this here branch, as it should. On repeat tries I can also observe failures, but not conistently. That is very strange, but I also don't know anything about vimtex's cache architecture to know if that could be the reason. I've tried inserting VimtexReloads and bwipeout!s everywhere, but couldn't get it to pass consistently.

why is not my much simpler version of the tests sufficient here?

You mean the two tex files with their own bibs? I wanted to reduce complexity while also testing more glob cases. But if my approach confuses the cache mechanism, then I should just implement your proposal to get the test to work reliably.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Apr 26, 2021

I'm not fully sure if the problem is caused by the caches, actually, but it seems like a probable cause. Still, when I looked into it, I could not find a consistent way to reproduce or avoid the issue.

You mean the two tex files with their own bibs? I wanted to reduce complexity while also testing more glob cases. But if my approach confuses the cache mechanism, then I should just implement your proposal to get the test to work reliably.

Yes, exactly. I understand the idea of reducing complexity and allowing more tests in a more automatic fashion. However, please alos note that the way you implement the tests is much harder to "reason" about. My suggestion may be more explicit and verbose, but it is also mostly trivial to reason about and understand. In my opinion, this is a good thing. It should also be quite easy to add more similar tests based on the same simple mechanism.

PS! This is getting into a long thread on testing technicalities where your suggested patch is clearly an improvement. I don't want to "scare" you from contributing by being pedantic. So, I just want to be clear that I already much appreciate your contribution and I won't mind to just write the test myself and merge this.

@TpmKranz TpmKranz force-pushed the fix-biblatex-glob branch from 1e7c67c to 1e0ff29 Compare July 7, 2021 13:21
@TpmKranz
Copy link
Copy Markdown
Contributor Author

TpmKranz commented Jul 7, 2021

I see you've credited me in the release notes for 2.5, yet I can't see any changes to autoload/vimtex/bib.vim.

I've reworked the test cases to be clearer and fixed another problem in the process. Hopefully, we can get this problem fixed now. :)

TpmKranz added 4 commits July 8, 2021 13:43
The fix in 2efe806 isn't used if biblatex
is detected, even though globbing is only possible with biblatex.

Since b7fbff1, that code path is only
used if there aren't better methods of detecting bib files.
That was okay because the only other method introduced was to parse
BibTeX's blg file and BibTeX can't handle globbing anyway.
But in 2536f04, support for biber's bcf
file was added without also adding globbing support.

Apparently, globbing can be disabled per resource, so filenames that are
candidates for globbing must be retained in the file list.
This should only have an effect with curly braces, though.
Globbing candidates that aren't actual filenames will be filtered out
with s:validate(), as before.
@TpmKranz TpmKranz force-pushed the fix-biblatex-glob branch from 1e0ff29 to a558e91 Compare July 8, 2021 11:51
@TpmKranz
Copy link
Copy Markdown
Contributor Author

TpmKranz commented Jul 8, 2021

Sorry for the repeat force-pushes, but I wanted to have all the tests for completions that should have worked in one commit.
After looking at what biber actually does (call perl's glob function), I've noticed another missing meta character I hadn't checked.
I don't think backslash and tilde are relevant, since vim's file handling functions should interpret them the same way that perl's glob would. If not (you'll know a lot more about how vim handles these than I could), please tell me.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 10, 2021

I see you've credited me in the release notes for 2.5, yet I can't see any changes to autoload/vimtex/bib.vim.

Huh, strange. That probably a mistake, perhaps because I noticed #2037 that was closed. Sorry about that; I hope you don't mind that I edit the release notes. You will then be properly credited in the next release notes.

I've reworked the test cases to be clearer and fixed another problem in the process. Hopefully, we can get this problem fixed now. :)

Great! I think the tests look good, except for some reason, they are failing. Do you immediately notice why?

Sorry for the repeat force-pushes, but I wanted to have all the tests for completions that should have worked in one commit.

No problem; I prefer logical commits anyway :)

Feel free to also rebase your PR on top of the most recent master. Of course, I'll make sure to do it anyway before I merge, but in the small chance of a merge conflict it may help to have your eyes on the conflict matter.

After looking at what biber actually does (call perl's glob function), I've noticed another missing meta character I hadn't checked.
I don't think backslash and tilde are relevant, since vim's file handling functions should interpret them the same way that perl's glob would. If not (you'll know a lot more about how vim handles these than I could), please tell me.

Yes, I think they work similarly.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 10, 2021

Tests fails with following message:

❯ make
Assertion failed!
Vim(let):E220: Missing }.
make: *** [Makefile:15: test_globbed_braces] Error 1

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 10, 2021

It seems the problem is here:

https://github.com/TpmKranz/vimtex/blob/0967d97e72f6fcfed7f85847373cc93f5b692611/autoload/vimtex/bib.vim#L95-L100

When I print the value of l:f that fails, it is "test_globbed_{1", which seems to make sense. The bracket is not matched, so the glob expression is not valid. Perhaps the regex must be more advanced? `=~# '[?]|{.}|[.*]'?

@TpmKranz
Copy link
Copy Markdown
Contributor Author

That must be vim-specific; I have to admit that I've been testing with neovim only, which doesn't throw an error for invalid globs. I'm not a fan of pre-checking potential globs for validity as that's already being done in glob, the regex would be quite opaque (PCRE maybe ^((\{(?1)\}|[^{}])*)$? No idea about a vim regex.) and it also shouldn't matter because we are only adding to a list of potential files and an invalid glob can't mean anything other than the literal filename (which is already in our list of candidates). So could we maybe just silent! the line with a comment to explain why?

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

That must be vim-specific;

Nope. It fails also on neovim (see the Github actions result here).

I'm not a fan of pre-checking potential globs for validity as that's already being done in glob, the regex would be quite opaque (PCRE maybe ^((\{(?1)\}|[^{}])*)$? No idea about a vim regex.) and it also shouldn't matter because we are only adding to a list of potential files and an invalid glob can't mean anything other than the literal filename (which is already in our list of candidates). So could we maybe just silent! the line with a comment to explain why?

Perhaps; if that would work. I don't mind checking more candidates, but we need to be sure the output is validated properly.

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

Which version of neovim are you on?

@TpmKranz
Copy link
Copy Markdown
Contributor Author

Which version of neovim are you on?

NVIM v0.4.4
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/builddir/build/BUILD/neovim-0.4.4/x86_64-redhat-linux-gnu/config -I/builddir/build/BUILD/neovim-0.4.4/src -I/usr/include -I/usr/include/lua-5.1 -I/builddir/build/BUILD/neovim-0.4.4/x86_64-redhat-linux-gnu/src/nvim/auto -I/builddir/build/BUILD/neovim-0.4.4/x86_64-redhat-linux-gnu/include
Compiled by mockbuild@koji

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

@clason
Copy link
Copy Markdown
Contributor

clason commented Jul 11, 2021

Can you try the latest release (v0.5.0)?

@TpmKranz
Copy link
Copy Markdown
Contributor Author

Can you try the latest release (v0.5.0)?

Fedora 34 doesn't yet carry that version and I'm not inclined to compile it myself, especially when the version used in the failed Github Action is the same as mine and it's therefore questionable whether the version itself is the problem.

For some reason, my neovim is unable to complete another test, even with MYVIM="nvim --headless -u NONE":

make -C test-indentation
16c16
<       & 2 \\
---
>     & 2 \\
18c18
<       & 4 \\
---
>     & 4 \\
make[1]: *** [Makefile:15: test_ampersands_reference] Error 1
make: *** [Makefile:18: test-indentation] Error 2

Dunno why that is, maybe I've just got an entirely broken installation. Maybe I should just do my tests in a container?

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

For some reason, my neovim is unable to complete another test, even with MYVIM="nvim --headless -u NONE":

You should not need to set the MYVIM; the defaul is nvim --headless. No need to add -u NONE, I think.

The tests pass on master both on my systems and on Github Actions, so this does seems somewhat strange. :\

lervag added a commit that referenced this pull request Jul 11, 2021
@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

I've think I've found a reasonable solution. Let me know what you think (see my extra commit).

@lervag lervag closed this Jul 11, 2021
@TpmKranz
Copy link
Copy Markdown
Contributor Author

Yeah, that'll do. I didn't know that vim could do error catching. A bit disappointing that my PR couldn't be merged but very glad that the problem's been fixed to your satisfaction now!
Thanks for all the work you put into this project and your patience with my PR; I very much appreciate it.

@TpmKranz
Copy link
Copy Markdown
Contributor Author

Oh sorry, I'm just now seeing that my commits have, in fact, been merged. No reason for me to be disappointed, then. :)

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

Yeah, that'll do. I didn't know that vim could do error catching.

Yes, as I often say, Vimscript is not as bad as many people think. But it is peculiar at times. ;)

A bit disappointing that my PR couldn't be merged but very glad that the problem's been fixed to your satisfaction now!
Thanks for all the work you put into this project and your patience with my PR; I very much appreciate it.

Oh sorry, I'm just now seeing that my commits have, in fact, been merged. No reason for me to be disappointed, then. :)

Yes, sorry if that was unclear. I rebased your commits on top of master, then added a minor commit where I made some changes that I believe were minor improvements. I try to keep the contributions from others clear and visible; I very much appreciate when others want to help and contribute!

And thanks for the kind words!

@lervag
Copy link
Copy Markdown
Owner

lervag commented Jul 11, 2021

By the way; the tests still fail. They pass on my system, so it must be a version or system related issue. Do you have any clue what might be wrong?

https://github.com/lervag/vimtex/runs/3042079001?check_suite_focus=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants