camspiers / snap

A fast finder system for neovim.
The Unlicense
483 stars 16 forks source link

Cache not working for me #67

Closed TyberiusPrime closed 3 years ago

TyberiusPrime commented 3 years ago

I have the following snap run definition

snap.register.map(
    {"n"},
    {"<leader>f"},
    function()
        snap.run {
            producer = snap.get "consumer.fzf"(snap.get "consumer.cache"snap.get("producer.ripgrep.file").args(rg_args))),
            select = snap.get "select.file".select,
            multiselect = snap.get "select.file".multiselect
            --    views = {snap.get'preview.file'}
        }
    end
)

But it kicks of a ripgrep run every time (which runs 5 seconds on my slow sshfs connection here). I'm probably using it wrong.

Also might I suggest a 'build once, then rebuild in background while showing last result' cache function? That way you'd get an updated output (eventually), but without any UI delays.

TyberiusPrime commented 3 years ago

Some basic debugging suggests that the local cache is always empty. And it's of course trivial if you understand how it works - I'm creating a new function, with a new local cache every time I call my mapping.

I need to define the producer outside of the snap.register.map call and it's callback function.

Might be worth mentioning in the documentation.

camspiers commented 3 years ago

Fzf and fzy already include a cache by default, it caches the return of ripgrep file etc while snap is open. You generally don't want to cache across snap runs.

TyberiusPrime commented 3 years ago

the operative words here being 'while snap is open'.

I can't wait 10 seconds for ripgrep to do it's thing over this slow link every time I want to switch to an unopened file.

Guess I'm the special case then.

Though I'm interestedwhat consumer.cache is supposed to be for

camspiers commented 3 years ago

You could create a cache that works across opens, the should be no problem, but you should make sure the cache is indexed by cwd, because different results get returned for different cwd's, but like you say, you will need to make sure that the cache doesn't get created on each time snap is opened.

cache is used to avoid every char you type running the producer again. The default behavior is that the producer gets run on each char entered, and this makes sense because we support producers that response differently to different filters.