vim-patch:9.1.0428: Tag guessing leaves wrong search history with very short names

Problem:  Tag guessing leaves wrong search history with very short names
          (after 9.1.0426).
Solution: Use the correct variable for pattern length (zeertzjq).

closes: vim/vim#14817

42cd192daa

Cherry-pick Test_tagbsearch() changes from patch 9.0.0767.
This commit is contained in:
zeertzjq
2024-05-22 05:35:21 +08:00
parent b86381f425
commit 59fe8ffdea
2 changed files with 21 additions and 5 deletions

View File

@@ -2978,7 +2978,7 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, bool keep_help)
// Guess again: "^char * \<func (" // Guess again: "^char * \<func ("
pbuflen = (size_t)snprintf(pbuf, LSIZE, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(", pbuflen = (size_t)snprintf(pbuf, LSIZE, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
tagp.tagname); tagp.tagname);
if (!do_search(NULL, '/', '/', pbuf, len, 1, search_options, NULL)) { if (!do_search(NULL, '/', '/', pbuf, pbuflen, 1, search_options, NULL)) {
found = 0; found = 0;
} }
} }

View File

@@ -1551,14 +1551,14 @@ func Test_tagbsearch()
\ "third\tXfoo\t3", \ "third\tXfoo\t3",
\ "second\tXfoo\t2", \ "second\tXfoo\t2",
\ "first\tXfoo\t1"], \ "first\tXfoo\t1"],
\ 'Xtags') \ 'Xtags', 'D')
set tags=Xtags set tags=Xtags
let code =<< trim [CODE] let code =<< trim [CODE]
int first() {} int first() {}
int second() {} int second() {}
int third() {} int third() {}
[CODE] [CODE]
call writefile(code, 'Xfoo') call writefile(code, 'Xfoo', 'D')
enew enew
set tagbsearch set tagbsearch
@@ -1618,9 +1618,25 @@ func Test_tagbsearch()
\ 'Xtags') \ 'Xtags')
call assert_fails('tag bbb', 'E426:') call assert_fails('tag bbb', 'E426:')
call delete('Xtags')
call delete('Xfoo')
set tags& tagbsearch& set tags& tagbsearch&
endfunc endfunc
" Test tag guessing with very short names
func Test_tag_guess_short()
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
\ "y\tXf\t/^y()/"],
\ 'Xt', 'D')
set tags=Xt cpoptions+=t
call writefile(['', 'int * y () {}', ''], 'Xf', 'D')
let v:statusmsg = ''
let @/ = ''
ta y
call assert_match('E435:', v:statusmsg)
call assert_equal(2, line('.'))
call assert_match('<y', @/)
set tags& cpoptions-=t
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab