mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 20:54:28 +08:00
[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:
@@ -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
|
||||||
|
|||||||
10
bin/tags.pl
10
bin/tags.pl
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user