lewis6991 / impatient.nvim

Improve startup time for Neovim
MIT License
1.19k stars 28 forks source link

Hashing fails when neovim is installed as an AppImage. #4

Closed nialov closed 3 years ago

nialov commented 3 years ago

Calls to vim.loop.fs_stat will fail for builtin lua files of neovim (such as /tmp/.mount_nvimYb1LQX/usr/share/nvim/runtime/lua/vim/treesitter/query.lua) in the impatient.lua hash function when neovim is installed as an AppImage. *I imagine the main cause is that AppImage makes a new `.mount_` directory on each launch (?).**

Because the call fails it returns nil which doesn't have the mtime key/attribute resulting in error on the fs_stat line.

Could check that the file exists and as at least temporary fix skip these builtin lua files if they have the .mount_ directory as a parent in their filetree? E.g.

    local function load_package_with_cache(name)
        local basename = name:gsub('%.', '/')
        local paths = {
            "lua/" .. basename .. ".lua", "lua/" .. basename .. "/init.lua"
        }
        for _, path in ipairs(paths) do
            local found = vim.api.nvim_get_runtime_file(path, false)
            if #found > 0 then
                local modpath = found[1]
                local f, err = loadfile(modpath)
                -- Check if AppImage rtp file
                if not string.find(modpath, ".mount_") then
                    M.cache[name] = {modpath, hash(modpath), string.dump(f)}
                    log('Creating cache for module', name)
                    M.dirty = true
                end

                return f or error(err)
            end
        end
        return nil
    end
lewis6991 commented 3 years ago

We can still cache them, for the hash we just need to strip the path prefix and replace it with something predictable. Maybe the version? The filename in the cache wont be very usable but the cache itself should be fine.

Only running an M1 MacBook at the moment so just trying to install an x64 VM so I can test this.

lewis6991 commented 3 years ago

So I wasn't able to figure out how to create a unique ID for a Neovim version. The closest I got was lua print(vim.inspect(vim.version())).

So instead I've fixed it so modules loaded from /tmp are never cached.