ctrlpvim / ctrlp.vim

Active fork of kien/ctrlp.vim—Fuzzy file, buffer, mru, tag, etc finder.
ctrlpvim.github.com/ctrlp.vim
Other
5.57k stars 260 forks source link

ctrlp cache uses getcwd() as basename, with autochdir this causes reindexing for files in the same project with different directory #605

Open char101 opened 2 years ago

char101 commented 2 years ago

Hi,

ctrlp#utils#cachefile by default uses getcwd() as the cache filename. And it is called in https://github.com/ctrlpvim/ctrlp.vim/blob/master/autoload/ctrlp.vim#L381 without any parameter.

When autochdir is set, opening ctrlp with files in the same project root but that belongs to different directory causes reindexing to occur.

Can't the cache file uses to project root as base filename instead?

char101 commented 2 years ago

What works for me

diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim
index d4445c8..0b074d4 100644
--- a/autoload/ctrlp.vim
+++ b/autoload/ctrlp.vim
@@ -379,7 +379,7 @@ fu! s:Reset(args)
 endf
 " * Files {{{1
 fu! ctrlp#files()
-       let cafile = ctrlp#utils#cachefile()
+       let cafile = ctrlp#utils#cachefile(s:dyncwd, 1)
        if g:ctrlp_newcache || !filereadable(cafile) || s:nocache(cafile)
                let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
                " Get the list of files
@@ -2637,7 +2637,7 @@ endf
 " Cache {{{2
 fu! s:writecache(cafile)
        if ( g:ctrlp_newcache || !filereadable(a:cafile) ) && !s:nocache()
-               cal ctrlp#utils#writecache(g:ctrlp_allfiles)
+               cal ctrlp#utils#writecache(g:ctrlp_allfiles, ctrlp#utils#cachedir(), a:cafile)
                let g:ctrlp_newcache = 0
        en
 endf
@@ -2670,7 +2670,7 @@ fu! s:insertcache(str)
                endfo
        en
        cal insert(data, str, pos)
-       cal s:writecache(ctrlp#utils#cachefile())
+       cal s:writecache(ctrlp#utils#cachefile(s:dyncwd, 1))
 endf
 " Extensions {{{2
 fu! s:mtype()