Skip to content

Commit a686459

Browse files
committed
fix: replace vim.fn.expand with vim.fs.normalize
Using vim.fs.normalize provides better path normalization across different operating systems. This change improves path handling consistency in file operations for the CopilotChat plugin. There's also a typo fix in the function name from 'normalie' to 'normalize' at one location.
1 parent 30795d9 commit a686459

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ function M.save(name, history_path)
785785
end
786786

787787
local history = vim.json.encode(client.history)
788-
history_path = vim.fn.expand(history_path)
788+
history_path = vim.fs.normalize(history_path)
789789
vim.fn.mkdir(history_path, 'p')
790790
history_path = history_path .. '/' .. name .. '.json'
791791
local file = io.open(history_path, 'w')
@@ -814,7 +814,7 @@ function M.load(name, history_path)
814814
return
815815
end
816816

817-
history_path = vim.fn.expand(history_path) .. '/' .. name .. '.json'
817+
history_path = vim.fs.normalize(history_path) .. '/' .. name .. '.json'
818818
local file = io.open(history_path, 'r')
819819
if not file then
820820
return

lua/CopilotChat/utils.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ end
114114
--- Finds the path to the user's config directory
115115
---@return string?
116116
function M.config_path()
117-
local config = vim.fn.expand('$XDG_CONFIG_HOME')
117+
local config = vim.fs.normalize('$XDG_CONFIG_HOME')
118118
if config and vim.fn.isdirectory(config) > 0 then
119119
return config
120120
end
121121
if vim.fn.has('win32') > 0 then
122-
config = vim.fn.expand('$LOCALAPPDATA')
122+
config = vim.fs.normalie('$LOCALAPPDATA')
123123
if not config or vim.fn.isdirectory(config) == 0 then
124-
config = vim.fn.expand('$HOME/AppData/Local')
124+
config = vim.fs.normalize('$HOME/AppData/Local')
125125
end
126126
else
127-
config = vim.fn.expand('$HOME/.config')
127+
config = vim.fs.normalize('$HOME/.config')
128128
end
129129
if config and vim.fn.isdirectory(config) > 0 then
130130
return config

0 commit comments

Comments
 (0)