Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a84a0ab

Browse files
fix: prevent trying to detach from never-attached buffers
1 parent a037c1f commit a84a0ab

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

‎lua/copilot/client/init.lua‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ local function on_filetype(bufnr)
184184

185185
-- This is to handle the case where the filetype changes after the buffer is already attached,
186186
-- causing the LSP to raise an error
187-
if util.get_buffer_previous_ft(bufnr) ~= vim.bo[bufnr].filetype then
187+
local previous_ft = util.get_buffer_previous_ft(bufnr)
188+
if previous_ft and (previous_ft ~= vim.bo[bufnr].filetype) then
188189
logger.trace("filetype changed, detaching and re-attaching")
189190
M.buf_detach_if_attached(bufnr)
190191
end

‎lua/copilot/util.lua‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ function M.set_buffer_previous_ft(bufnr, filetype)
150150
end
151151

152152
---@param bufnr integer
153-
---@return string
153+
---@return string|nil
154154
function M.get_buffer_previous_ft(bufnr)
155155
local ok, result = pcall(vim.api.nvim_buf_get_var, bufnr, M.VAR_PREVIOUS_FT)
156-
return (ok and result) or ""
156+
return (ok and result) or nil
157157
end
158158

159159
---@param cmd string|string[]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /