rest.nvim icon indicating copy to clipboard operation
rest.nvim copied to clipboard

packer: opt=true causes rest.nvim to fail

Open jceb opened this issue 3 years ago • 3 comments

I set up rest.nvim as an optional dependency like this:

    use({
        "NTBBloodbath/rest.nvim",
        requires = { "nvim-lua/plenary.nvim" },
        opt = true,
        ft = { "http" },
        config = function()
            require("rest-nvim").setup({
                result_split_horizontal = false,
            })
            vim.cmd([[
            au FileType http nmap <buffer> <silent> <C-j> <Plug>RestNvim
            ]])
        end,
    })

When I open a file, set the file type to http and press <C-j> I get the following error:

Error executing luv callback:
...site/pack/packer/start/plenary.nvim/lua/plenary/path.lua:614: ENOENT: no such file or directory: /tmp/plenary_curl_b3524790.headers

With opt=false everything works fine.

jceb avatar Oct 21 '21 14:10 jceb

Hey, this is being a bit odd to me because the error comes from plenary so I don't know exactly what's going on under the hood :eyes:

Also there's no need for opt = true if you're already using ft, unless you also want to lazy-load plenary but still this shouldn't be a problem hmm do you have any ftdetect file to automatically detect http files?

NTBBloodbath avatar Oct 22 '21 08:10 NTBBloodbath

Yes, good point that opt = true is optional in this case. I have an autocommand that sets the http file type for file names matching *.http.

I also find it weird that the error comes from plenary. Are you able to reproduce the error?

jceb avatar Oct 22 '21 08:10 jceb

I am not exactly sure what you are trying to do here...but maybe this helps a bit. I don't use Packer but still have setup rest.nvim as an optional plugin. Don't really know if this improves loading time or performance. It's mere an experiment:

Install the plugin with Paq, Packer should be quite similar I guess:

require("paq-nvim")({
....
	{ "NTBBloodbath/rest.nvim", opt = true },
....
})

Then in a module required from init.lua:

vim.cmd([[ au BufEnter *.http call v:lua.require("plugins.rest").loadRestClient() ]])

local M = {}

function M.loadRestClient()
	if vim.g.loaded_rest_nvim ~= 1 then
		vim.cmd([[ packadd rest.nvim ]])
		require("rest-nvim").setup({
			result_split_horizontal = false,
			skip_ssl_verification = false,
			highlight = { enabled = true, timeout = 150 },
			jump_to_request = false,
		})
		vim.api.nvim_set_keymap("n", "<leader>r", "<Plug>RestNvim", { nowait = true })
		vim.api.nvim_set_keymap("n", "<leader>pr", "<Plug>RestNvimPreview", { nowait = true })
		vim.cmd("command! RestNvim lua require('rest-nvim').run()")
		vim.cmd("command! RestNvimPreview lua require('rest-nvim').run(true)")
	end
end

return M

This seems to load the plugin correctly when opening a .http file. For other files the commands and mappings are not available.

lkoning avatar Dec 01 '21 09:12 lkoning

feel free to reopen if you still have the issue.

teto avatar Aug 22 '22 18:08 teto