michaelb / sniprun

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
MIT License
1.43k stars 46 forks source link

Wrong cache directory path on linux #241

Closed yztxwd closed 1 year ago

yztxwd commented 1 year ago

Describe the bug :SnipInfo gave me the error

E5108: Error executing lua ...e/jmy5455/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:281: attempt to index local 'file' (a nil value)
stack traceback:
        ...e/jmy5455/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:281: in function 'lines_from'
        ...e/jmy5455/.local/share/nvim/lazy/sniprun/lua/sniprun.lua:326: in function 'info'
        [string ":lua"]:1: in main chunk

To Reproduce :SnipInfo

Expected behavior Give me a table on compatibility

Environment:

Additional context I found out this is due to somehow the default_cache_dir was set to a Macos one "/home/jmy5455/Library/Caches", after looking into the code. It seems like it's due to

    if vim.fn.isdirectory(os.getenv("HOME").."/Library/Caches") then -- we're (probably) on MacOS
        default_cache_dir = os.getenv("HOME").."/Library/Caches"
    end

vim.fn.isdirectory(...) returned 0, then it's deemed as true, which caused the issue, i'm very new to lua so not sure if this is what it should behave like.

I fixed the issue by simply replace the condition with if (vim.fn.isdirectory(os.getenv("HOME").."/Library/Caches")~=0) then -- we're (probably) on MacOS

Now :SnipInfo works well

michaelb commented 1 year ago

Thanks!

Your suggestion will be applied in the next version (and will live in the dev branch in the meantime), I will close this issue when I merge it into the master branch.

It's a bit strange that you encountered this issue, I'm also on Linux (obviously no ~/Library/Caches) and I didn't have it. I hope no MacOS users will come screaming back because you broke their :SnipInfo