jackMort / ChatGPT.nvim

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

Error executing :ChatGPT #173

Closed Wietse closed 1 year ago

Wietse commented 1 year ago

Hello,

I'm using: NVIM v0.10.0-dev-4163+g05928fe29-Homebrew Build type: Release LuaJIT 2.1.0-beta3

I've just installed the plugin but when I execute :ChatGPT I get following error:

Error executing Lua callback: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_deep_extend'
        .../pack/packer/start/ChatGPT.nvim/lua/chatgpt/settings.lua:72: in function 'get_settings_panel'
        ...te/pack/packer/start/ChatGPT.nvim/lua/chatgpt/module.lua:67: in function 'open_chat'
        ...te/pack/packer/start/ChatGPT.nvim/lua/chatgpt/module.lua:279: in function 'openChat'
        ...nvim/site/pack/packer/start/ChatGPT.nvim/lua/chatgpt.lua:25: in function 'openChat'
        ...m/site/pack/packer/start/ChatGPT.nvim/plugin/chatgpt.lua:2: in function <...m/site/pack/packer/start/ChatGPT.nvim/plugin/chatgpt.lua:1>

Do you know how to fix this?

Regards, Wietse

shutils commented 1 year ago

Hi @Wietse

Could you write your plugin settings here?

This plugin needs to be set up first. Here is an example of plugin loading when using Packer:

-- Packer
use({
  "jackMort/ChatGPT.nvim",
    config = function()
      require("chatgpt").setup()
    end,
    requires = {
      "MunifTanjim/nui.nvim",
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim"
    }
})
Wietse commented 1 year ago

Hello @shutils ,

Thanks for your time!

Could you write your plugin settings here?

Indeed I use Packer. I took the setup code from the readme. I'm not familiar with lua, so I tend to keep my nvim config as simple as possible:

        -- ChatGPT
        -- https://github.com/jackMort/ChatGPT.nvim
        use({
            "jackMort/ChatGPT.nvim",
            config = function() require("chatgpt").setup({}) end,
            requires = {
                "MunifTanjim/nui.nvim",
                "nvim-lua/plenary.nvim",
                "nvim-telescope/telescope.nvim"
            }
        })

This is inside the require('packer').startup(function(use) ... ) function.

No, not from the readme, from this article: https://dev.to/xxxuutaxxx/awesome-plugin-chatgpt-with-neovim-571d

shutils commented 1 year ago

@Wietse

I tried copying your configuration but couldn't reproduce the issue. I apologize for not being able to help you.

This is my plugins.lua file when I tried it. I hope it can be helpful for your reference.

local fn = vim.fn
local autocmd = vim.api.nvim_create_autocmd

-- Automatically install packer
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
  PACKER_BOOTSTRAP = fn.system({
    "git",
    "clone",
    "--depth",
    "1",
    "https://github.com/wbthomason/packer.nvim",
    install_path,
  })
  print("Installing packer close and reopen Neovim...")
  vim.cmd([[packadd packer.nvim]])
end

-- Autocommand that reloads neovim whenever you save the plugins.lua file
autocmd("BufWritePost", { pattern = "plugins.lua", command = ":source <afile> | PackerSync" })

-- Use a protected call so we don't error out on first use
local status_ok, packer = pcall(require, "packer")
if not status_ok then
  return
end

-- Have packer use a popup window
packer.init({
  display = {
    open_fn = function()
      return require("packer.util").float({ border = "rounded" })
    end,
  },
})

-- Install your plugins here
return packer.startup(function(use)
  -- My plugins here

  use({ "wbthomason/packer.nvim" })

  -- chatGpt
  use({
    "jackMort/ChatGPT.nvim",
    config = function() require("chatgpt").setup({}) end,
    requires = {
      "MunifTanjim/nui.nvim",
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
    },
  })

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if PACKER_BOOTSTRAP then
    require("packer").sync()
  end
end)
joona commented 1 year ago

I had the same issue, with the configuration example.

However, today I noticed that there's a new commit in the master, which seems to fix the issue https://github.com/jackMort/ChatGPT.nvim/commit/cd060d2dd9abb72e24d7921cdbcf3f57cc720105

Wietse commented 1 year ago

I had the same issue, with the configuration example.

However, today I noticed that there's a new commit in the master, which seems to fix the issue cd060d2

Thanks! It seems to be functioning now! I only need to learn how to use it now :-)

rhosoftpl commented 1 year ago

Hello, I have the same problem as above

image

and this is my config

return require('packer').startup(
    function(use)
        use 'wbthomason/packer.nvim'
        use({
            "jackMort/ChatGPT.nvim",
            config = function()
                require("chatgpt").setup()
            end,
            requires = {
                "MunifTanjim/nui.nvim",
                "nvim-lua/plenary.nvim",
                "nvim-telescope/telescope.nvim"
            }
        })
        use {
            'nvim-telescope/telescope.nvim',
            tag = '0.1.0',
            requires = { {
                'nvim-lua/plenary.nvim',
            } }
        }
        use {
            'nvim-telescope/telescope-fzf-native.nvim',
            run = 'make'
        }
        use {
            'nvim-treesitter/nvim-treesitter',
            run = ':TSUpdate'
        }
...
Wietse commented 1 year ago

Hello, I have the same problem as above

As @joona pointed out: make sure to update the code. :PackerUpdate That's what solved it for me.

rhosoftpl commented 1 year ago

Hello, I have the same problem as above

As @joona pointed out: make sure to update the code. :PackerUpdate That's what solved it for me.

Wish to work for me , but unfortunately not. I'll wait then. Thanks.

joona commented 1 year ago

I ran :PackerUpdate and :PackerSync after that. PackerSync or PackerCompile might be required if you've precompiled the packer plugins.