Skip to content

Commit 6fa90e6

Browse files
committed
fix: only clear autocmd group if it was created
Fixes #503
1 parent 6ea6bcc commit 6fa90e6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lua/copilot/client/init.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ local client_config = require("copilot.client.config")
88
local is_disabled = false
99

1010
---@class CopilotClient
11+
---@field augroup string|nil
1112
---@field id integer|nil
1213
---@field capabilities lsp.ClientCapabilities | nil
1314
---@field config vim.lsp.ClientConfig | nil
1415
---@field startup_error string | nil
1516
---@field initialized boolean
1617
local M = {
17-
augroup = "copilot.client",
18+
augroup = nil,
1819
id = nil,
1920
capabilities = nil,
2021
config = nil,
@@ -150,7 +151,11 @@ function M.setup()
150151
is_disabled = false
151152

152153
M.id = nil
153-
vim.api.nvim_create_augroup(M.augroup, { clear = true })
154+
155+
-- nvim_clear_autocmds throws an error if the group does not exist
156+
local augroup = "copilot.client"
157+
vim.api.nvim_create_augroup(augroup, { clear = true })
158+
M.augroup = augroup
154159

155160
vim.api.nvim_create_autocmd("FileType", {
156161
group = M.augroup,
@@ -165,7 +170,10 @@ end
165170
function M.teardown()
166171
is_disabled = true
167172

168-
vim.api.nvim_clear_autocmds({ group = M.augroup })
173+
-- nvim_clear_autocmds throws an error if the group does not exist
174+
if M.augroup then
175+
vim.api.nvim_clear_autocmds({ group = M.augroup })
176+
end
169177

170178
if M.id then
171179
vim.lsp.stop_client(M.id)

0 commit comments

Comments
 (0)