Skip to content

refactor: do not require chat on plugin load #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions plugin/CopilotChat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if vim.fn.has('nvim-' .. min_version) ~= 1 then
return
end

local chat = require('CopilotChat')

-- Setup highlights
vim.api.nvim_set_hl(0, 'CopilotChatStatus', { link = 'DiagnosticHint', default = true })
vim.api.nvim_set_hl(0, 'CopilotChatHelp', { link = 'DiagnosticInfo', default = true })
Expand All @@ -21,6 +19,7 @@ vim.api.nvim_set_hl(0, 'CopilotChatSeparator', { link = '@punctuation.special.ma

-- Setup commands
vim.api.nvim_create_user_command('CopilotChat', function(args)
local chat = require('CopilotChat')
local input = args.args
if input and vim.trim(input) ~= '' then
chat.ask(input)
Expand All @@ -33,31 +32,40 @@ end, {
range = true,
})
vim.api.nvim_create_user_command('CopilotChatPrompts', function()
local chat = require('CopilotChat')
chat.select_prompt()
end, { force = true, range = true })
vim.api.nvim_create_user_command('CopilotChatModels', function()
local chat = require('CopilotChat')
chat.select_model()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatAgents', function()
local chat = require('CopilotChat')
chat.select_agent()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatOpen', function()
local chat = require('CopilotChat')
chat.open()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatClose', function()
local chat = require('CopilotChat')
chat.close()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatToggle', function()
local chat = require('CopilotChat')
chat.toggle()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatStop', function()
local chat = require('CopilotChat')
chat.stop()
end, { force = true })
vim.api.nvim_create_user_command('CopilotChatReset', function()
local chat = require('CopilotChat')
chat.reset()
end, { force = true })

local function complete_load()
local chat = require('CopilotChat')
local options = vim.tbl_map(function(file)
return vim.fn.fnamemodify(file, ':t:r')
end, vim.fn.glob(chat.config.history_path .. '/*', true, true))
Expand All @@ -69,9 +77,11 @@ local function complete_load()
return options
end
vim.api.nvim_create_user_command('CopilotChatSave', function(args)
local chat = require('CopilotChat')
chat.save(args.args)
end, { nargs = '*', force = true, complete = complete_load })
vim.api.nvim_create_user_command('CopilotChatLoad', function(args)
local chat = require('CopilotChat')
chat.load(args.args)
end, { nargs = '*', force = true, complete = complete_load })

Expand Down
Loading