[Tags] Use 'readtags' if query string is given

This pre-filtering is critical when working with large tag files.

'readtags' can perform a binary search for the given prefix string
but fzf has to load the entire file into memory just to start searching.

Close #1529
Close #1524
This commit is contained in:
Junegunn Choi
2024-03-11 11:54:08 +09:00
parent 8ea9574b3e
commit 0b3e015ad8
2 changed files with 11 additions and 2 deletions

View File

@@ -1110,8 +1110,9 @@ function! fzf#vim#tags(query, ...)
endfor endfor
let opts = v2_limit < 0 ? ['--algo=v1'] : [] let opts = v2_limit < 0 ? ['--algo=v1'] : []
let args = insert(map(tagfiles, 'fzf#shellescape(fnamemodify(v:val, ":p"))'), fzf#shellescape(a:query), 0)
return s:fzf('tags', { return s:fzf('tags', {
\ 'source': 'perl '.fzf#shellescape(s:bin.tags).' '.join(map(tagfiles, 'fzf#shellescape(fnamemodify(v:val, ":p"))')), \ 'source': join(['perl', fzf#shellescape(s:bin.tags), join(args)]),
\ 'sink*': s:function('s:tags_sink'), \ 'sink*': s:function('s:tags_sink'),
\ 'options': extend(opts, ['--nth', '1..2', '-m', '-d', '\t', '--tiebreak=begin', '--prompt', 'Tags> ', '--query', a:query])}, a:000) \ 'options': extend(opts, ['--nth', '1..2', '-m', '-d', '\t', '--tiebreak=begin', '--prompt', 'Tags> ', '--query', a:query])}, a:000)
endfunction endfunction

View File

@@ -2,8 +2,16 @@
use strict; use strict;
my $prefix = shift @ARGV;
foreach my $file (@ARGV) { foreach my $file (@ARGV) {
open my $lines, $file; my $lines;
if ($prefix eq "") {
open $lines, $file;
} else {
# https://perldoc.perl.org/perlopentut#Expressing-the-command-as-a-list
open $lines, '-|', 'readtags', '-t', $file, '-e', '-p', $prefix;
}
while (<$lines>) { while (<$lines>) {
unless (/^\!/) { unless (/^\!/) {
s/^[^\t]*/sprintf("%-24s", $&)/e; s/^[^\t]*/sprintf("%-24s", $&)/e;