mistweaverco / kulala.nvim

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

Question regarding support for http-client.env.json files #15

Closed t-eichmann closed 3 months ago

t-eichmann commented 3 months ago

As described here https://learn.microsoft.com/en-us/aspnet/core/test/http-files?view=aspnetcore-8.0#environment-files environment files in the http-client.env.json format allow to specify different environments (in the example dev and remote). Is there a way to address/load different environments specified in these files in .http files? That would be a pretty neat feature if it doesn't already exist.

gorillamoe commented 3 months ago

Oh, I missed that one. Will be implementing this now. Give me 5 minutes to get a coffee ☕ an then we will rock this!

gorillamoe commented 3 months ago

There will be a .set_default_env(env) function exposed.

If you omit the env and call it like .set_default_env() it'll show a telescope picker, if you have one installed, otherwise you can simply call it with your desired env key.

t-eichmann commented 3 months ago

That sounds nice, do you plan a way to display the currently selected environment? Maybe added to the overlay that displays request execution time or a possibility to display it in the status bar.

gorillamoe commented 3 months ago

or a possibility to display it in the status bar

That would be awesome. Can you open up another issue with "Display selected environment in statusbar", please?

t-eichmann commented 3 months ago

If I have an http-client.env.json and try to run a request without selecting an environment first I get an error message kulala.nvim/lua/kulala/parser/env.lua:27: attempt to concatenate local 'selected_env_name' (a nil value) It might be good idea to display a warning if no environment is selected and/or store the last used environment somewhere.

gorillamoe commented 3 months ago

If I have an http-client.env.json and try to run a request without selecting an environment first I get an error message kulala.nvim/lua/kulala/parser/env.lua:27: attempt to concatenate local 'selected_env_name' (a nil value) It might be good idea to display a warning if no environment is selected and/or store the last used environment somewhere.

Can you check if that's already fixed with the latest commits?

I was thinking of persisting the selected value also.. but then I decided against it, because I was thinking that you might have different key names in different projects and that would cause headaches. It should always default to dev on a frest start of neovim :)

t-eichmann commented 3 months ago

The issue is still there. Can you maybe give us an option in the configuration to specify a default environment? On my system my development environment is tagged 'local' while 'dev' is one of our development servers, so having it default to 'dev' would in my special case be rather inconvenient.

gorillamoe commented 3 months ago

The option is already there:

https://github.com/mistweaverco/kulala.nvim?tab=readme-ov-file#simple-configuration

I see why there is a problem, I have to extend the table, will fix asap.

t-eichmann commented 3 months ago

Also, I have other weird behavior. Directly after starting neovim and navigating to my .http file I can not select an environment using lua require('kulala').set_selected_env(), the telescope picker just doesn't open. If I run a request, getting that error message, suddenly the picker works again.

t-eichmann commented 3 months ago

The option is already there:

https://github.com/mistweaverco/kulala.nvim?tab=readme-ov-file#simple-configuration

I see why there is a problem, I have to extend the table, will fix asap.

Sorry, I missed that option. Anyways, even after setting a deault in my configuration I have the problem with the environment picker.

gorillamoe commented 3 months ago

That's weird, can you double check, if you're on the latest commit, because I had this bug where the picker would not show up too, that was because the env wasn't loaded, because I previously only loaded the env on a request start.

Then I added this line https://github.com/mistweaverco/kulala.nvim/blob/main/lua/kulala/init.lua?plain=1#L12

To make sure the env gets loaded when setup is called.

t-eichmann commented 3 months ago

Yes, I am on the latest commit and checked, the mentioned line is there, but the problem persists. Might be something with my system configuration in general, I just installed lualine to check if displaying the selected environment works (I used the statusbar from mini.nvim before, but am open to change) and that doesn't seem to work either.

t-eichmann commented 3 months ago

Nevermind the issues with the statusbar, that was just me being to stupid to configure lualine correctly.

gorillamoe commented 3 months ago

Can you upload a minimal reproducible example of your config and a .http file somewhere? Or join the Discord server an upload it there? I want to fix that nasty 🤢 bug

t-eichmann commented 3 months ago

My lazy configuration file for kulala

return {
  'mistweaverco/kulala.nvim',
  opts = { default_env = 'local' },
  config = function()
    local kulala = require 'kulala'
    vim.keymap.set('n', '<leader>pr', kulala.run, { desc = 'Send HTTP [R]equest' })
    vim.keymap.set('n', '<leader>pt', kulala.toggle_view, { desc = '[T]oggle View headers/body' })
    vim.keymap.set('n', '<leader>pe', kulala.set_selected_env, { desc = 'Select [E]nvironment' })
  end,
}

dependencies = { 'nvim-telescope/telescope.nvim' }, Basic envirnment file:

{
  "local": {
    "host": "https://api.isevenapi.xyz"
  }
}

HTTP-file

GET {{host}}/api/iseven/12/
Accept: application/json

Or do you need my entire nvim config?

gorillamoe commented 3 months ago

Ah, you need to call the Kulala setup function, even if empty. It sets most things up.

gorillamoe commented 3 months ago

Something like this should work

return {
  'mistweaverco/kulala.nvim',
  config = function()
    local kulala = require 'kulala'
    kulala.setup({ default_env = 'local' })
    vim.keymap.set('n', '<leader>pr', kulala.run, { desc = 'Send HTTP [R]equest' })
    vim.keymap.set('n', '<leader>pt', kulala.toggle_view, { desc = '[T]oggle View headers/body' })
    vim.keymap.set('n', '<leader>pe', kulala.set_selected_env, { desc = 'Select [E]nvironment' })
  end,
}
t-eichmann commented 3 months ago

Thanks, now it works, again me being to stupid to set things up correctly. Sorry for causing you extra work.

gorillamoe commented 3 months ago

No worries, all good.

You came along with quite a good catches, so I owe you one. Thanks for beta testing this little baby!

t-eichmann commented 3 months ago

The thanks goes right back to you, with your relentless work in the last days you made my Postman setup entirely obsolete, that's more than I could wish for.