jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.67k stars 311 forks source link

Add in a new setup option for asynchronously loading API key #203

Closed elliottminns closed 1 year ago

elliottminns commented 1 year ago

The setup option of api_key_cmd is great, but it's performed synchronously. As I use a password store backed by a Yubikey, this can cause a significant delay when opening up Neovim.

In order to solve this, I've added a new setup option of async_api_key_cmd which uses plenary.job to asynchronously load the API key. For me, this improves the performance of opening up neovim and makes the plugin usable again.

There are some caveats with this, however.

You can only specify a command that follows the following format:

<cmd> <args>

Anything with piping, won't work. i.e.

<cmd> <args> | <cmd2>

Therefore, I opted to add a new setup configuration value, to ensure this does not break existing configurations. There may be a way to improve on this so that any command can be performed by the plenary job module.

jackMort commented 1 year ago

Great work, thanks! Could you just fix the styling errors to pass checks?

jackMort commented 1 year ago

As @MunifTanjin suggested, could you please just keep the api_key_cmd and use your asynchronous logic there?

elliottminns commented 1 year ago

Absolutely. I'll make that change today!