Skip to content

Commit 903a66a

Browse files
committed
refactor: simplify cwd detection
Turns out nvim_win_get_var was a drama queen, throwing exceptions whenever it couldn't find its precious variable - like a toddler having a meltdown when they can't find their favorite toy. Switched to vim.w, the more chill cousin who just returns nil and goes about their day when something's missing. Now our code won't have an existential crisis just because cchat_cwd wasn't set for one window. No more exception-al behavior, just peaceful, quiet coding.
1 parent 2c2256b commit 903a66a

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ function M.setup(config)
13191319
vim.api.nvim_create_autocmd({ 'VimEnter', 'WinEnter' }, {
13201320
group = augroup,
13211321
callback = function()
1322-
vim.api.nvim_win_set_var(0, 'cchat_cwd', vim.fn.getcwd())
1322+
vim.w.cchat_cwd = vim.fn.getcwd()
13231323
end,
13241324
})
13251325
end

lua/CopilotChat/utils.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ function M.win_cwd(winnr)
176176
return '.'
177177
end
178178

179-
local ok, dir = pcall(vim.api.nvim_win_get_var, winnr, 'cchat_cwd')
180-
if not ok or not dir or dir == '' then
179+
local dir = vim.w[winnr].cchat_cwd
180+
if not dir or dir == '' then
181181
return '.'
182182
end
183183

0 commit comments

Comments
 (0)