mistweaverco / kulala.nvim

A minimal 🤏 HTTP-client 🐼 interface 🖥️ for Neovim ❤️.
https://kulala.mwco.app
MIT License
668 stars 31 forks source link

Bad argument #1 to 'ipairs' #214

Closed Flamme13 closed 1 month ago

Flamme13 commented 2 months ago

Tell me how can I solve this problem. Everything was fine before, but now when I try to make a request, an error appears:

Error executing vim.schedule lua callback: ...l/share/nvim/lazy/kulala.nvim/lua/kulala/parser/init.lua:374: bad argument #1 to 'ipairs' (table expected, got nil)
gorillamoe commented 2 months ago

Can you post your config?

Flamme13 commented 2 months ago

My config for the plugin:

return {
    "mistweaverco/kulala.nvim",
    event = "VeryLazy",
    config = function()
        require("kulala").setup({
                      default_view = "headers_body",
                })

        vim.api.nvim_set_keymap("n", "<C-\\>", ":lua require('kulala').run()<CR>", { noremap = true, silent = true })
    end,
}

I didn't change anything in the config, but after the update this error started to appear.

Flamme13 commented 2 months ago
==============================================================================
kulala: require("kulala.health").check()

- {kulala.nvim} version 3.7.0
- OK {curl} found

Checking formatters ~
- WARNING {text/html} formatter not found
- OK {application/json} formatter: jq .
- WARNING {application/xml} formatter not found

==============================================================================
gorillamoe commented 2 months ago

What does lua require("kulala").version() print?

And, can you also post a basic stripped down version of the .http file you try to run requests on?

d4be4st commented 2 months ago

Same issue

image

trying

GET http://localhost:3000/config
gorillamoe commented 2 months ago

Oh, Shit, I think I know the issue. I think fenced code block support might have broken it for you.

When you're in the http file, what does :set buftype give you?

d4be4st commented 2 months ago

It is not set

image

gorillamoe commented 2 months ago

Can you try to set it to http and run a request?

d4be4st commented 2 months ago

Actually it seems i just needed to set filetype

It works with

filetype=http
buftype=

setting filetype="" raises the OP error

gorillamoe commented 2 months ago

Yeah, will push a fix. Then this is due to the newly introduced fenced code block support

gorillamoe commented 2 months ago

Thanks for catching this! ❤️🙏🏾

gorillamoe commented 2 months ago

Fix should be in main now. Re-open if the issue still persists, please.

franckrasolo commented 1 month ago

@gorillamoe I can confirm that this issue persists on the main branch at the time of writing.

franckrasolo commented 1 month ago

As a workaround for the time being, I've ended up adding the following keymap to the plugin configuration (LazyVim):

{
  keys = {
    { "<leader>RN", "<cmd>enew<cr><cmd>set filetype=http<cr>", desc = "Scratch buffer" }
  }
}

or, if you'd rather stick to pure Lua:

{
  keys = {
    { "<leader>RS", desc = "Scratch buffer",
      function()
        vim.cmd.enew()
        vim.bo.filetype = "http"
      end
    }
  }
}
franckrasolo commented 1 month ago

Ah, there's also the scratchpad method!

require("kulala").scratchpad()
gorillamoe commented 1 month ago

So just to make I understand this correctly, the issue is that you open a buffer which has no file type set and the run kulala.run right?

We should catch that error and display an error message, but it won't work, because kulala runs either on http and rest files (with the file type set) or anything else within fenced code blocks.

The only exception to this is the scratchpad() function from kulala itself, which takes care setting the correct file type.

So to sum it up: kulala only runs on files with either http or rest as file type or the scratchpad. For anything else Kulala assumes you must be in a file with a fenced code block (like markdown files ..)

franckrasolo commented 1 month ago

So just to make I understand this correctly, the issue is that you open a buffer which has no file type set and the run kulala.run right?

Yes, that's right. I agree about the need to handle this edge case gracefully somehow.

I've settled for these keymaps in the end and I'm unlikely to tweak them any further:

keys = {
  { "<leader>Ra", desc = "Open scratchpad",
    function()
      require("kulala").scratchpad()
    end,
    { noremap = true, silent = true }
  },
  { "<leader>Rb", desc = "Open scratchpad (empty)",
    function()
      vim.cmd.edit(require("kulala.globals").SCRATCHPAD_ID)
      vim.bo.buftype  = "nofile"
      vim.bo.filetype = "http"
    end,
    { noremap = true, silent = true }
  },
  { "<leader>Rc", desc = "Close scratchpad",
    function()
      require("kulala").close()
      vim.cmd.bdelete { args = { require("kulala.globals").SCRATCHPAD_ID }, bang = true }
    end,
    { noremap = true, silent = true }
  },
}

Later, I may also try executing a request from within a fenced code block.