zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.64k stars 75 forks source link

Fails to load with get_runtime_dir() #177

Closed mayakerostasia closed 1 year ago

mayakerostasia commented 1 year ago

Pretty sure this is probably not a problem with copilot.lua specifically but I don't know how where to look to fix it

Error executing vim.schedule lua callback: [string "..."]:0: attempt to call global 'get_runtime_dir' (a nil value)
stack traceback:
        [string "..."]: in function 'fn'
        vim/_editor.lua:495: in function 'cb'
        vim/_editor.lua:263: in function <vim/_editor.lua:262>

Here's the config

  use { "zbirenbaum/copilot.lua",
    event = { "VimEnter" },
    config = function()
      vim.defer_fn(function()
        require("copilot").setup {
          plugin_manager_path = get_runtime_dir() .. "/site/pack/packer",
          suggestion = {
            enabled = true,
            auto_trigger = false,
            debounce = 75,
            keymap = {
              accept = "<C-J>",
              accept_word = false,
              accept_line = false,
              next = "<C-j>",
              prev = "<C-k>",
              dismiss = "<C-\\>",
            },

          },
          filetypes = {
            markdown = true, -- overrides default
            terraform = true, -- disallow specific filetype
            yaml = true, -- disallow specific filetype
            ansible = true, -- disallow specific filetype
            sh = function ()
              if string.match(vim.fs.basename(vim.api.nvim_buf_get_name(0)), '^%.env.*') then
                -- disable for .env files
                return false
              end
              return true
            end,
          },
        }
      end, 100)
    end,
  }

  use { "zbirenbaum/copilot-cmp",
    after = { "copilot.lua" },
    config = function()
      require("copilot_cmp").setup()
    end,
  }

Even removing plugin manager path causes the same or a similar error

MunifTanjim commented 1 year ago

This is happening because you're calling get_runtime_dir. Not sure where you got that function, but it doesn't exist in Neovim.

Also copilot.lua doesn't even accept any plugin_manager_path option. Please follow the documentation at: https://github.com/zbirenbaum/copilot.lua/blob/master/README.md

MunifTanjim commented 1 year ago

Just remove the plugin_manager_path option, remove the vim.defer_fn wrapping, follow the docs from https://github.com/zbirenbaum/copilot.lua/blob/master/README.md and the guide from https://github.com/zbirenbaum/copilot.lua/discussions/99#discussioncomment-4483942

It should work as expected.