From 1520641a04b502a755dc84866294b99600d2c9dc Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Tue, 7 Jan 2025 13:02:43 +0100 Subject: [PATCH] feat: add symlink detection --- lua/chatgpt_nvim/context.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lua/chatgpt_nvim/context.lua b/lua/chatgpt_nvim/context.lua index 53ef6b6..55b1933 100644 --- a/lua/chatgpt_nvim/context.lua +++ b/lua/chatgpt_nvim/context.lua @@ -1,9 +1,6 @@ local M = {} local uv = vim.loop --- Remove local config = require('chatgpt_nvim.config') so we don't load config each time --- We'll accept a 'conf' parameter in our functions instead --- local config = require('chatgpt_nvim.config') local function load_gitignore_patterns(root, conf) local gitignore_path = root .. "/.gitignore" @@ -80,6 +77,18 @@ local function scandir(dir, ignore_patterns, files, conf) table.insert(files, fullpath) elseif ent.type == "directory" and ent.name ~= ".git" then scandir(fullpath, ignore_patterns, files, conf) + elseif ent.type == "link" then + local link_target = uv.fs_readlink(fullpath) + if link_target then + local st = uv.fs_stat(link_target) + if st and st.type == "directory" then + table.insert(files, fullpath .. " (symlink to directory " .. link_target .. ")") + else + table.insert(files, fullpath .. " (symlink to file " .. link_target .. ")") + end + else + table.insert(files, fullpath .. " (symlink)") + end end end end @@ -89,7 +98,6 @@ local function scandir(dir, ignore_patterns, files, conf) end function M.get_project_files(directories, conf) - -- conf is passed in from outside so we don't load config repeatedly local root = vim.fn.getcwd() local ignore_patterns = load_gitignore_patterns(root, conf) local all_files = {} @@ -146,4 +154,4 @@ function M.get_file_contents(files, conf) return table.concat(sections, "\n") end -return M \ No newline at end of file +return M