feat(sidebar): support files outside of the current working directory. (#1065)

This commit is contained in:
Christopher Brewin
2025-01-12 01:15:13 +10:00
committed by GitHub
parent 24641d8264
commit f401983737
4 changed files with 24 additions and 3 deletions

View File

@@ -39,6 +39,15 @@ function M.exists(filepath)
return stat ~= nil
end
function M.is_in_cwd(filepath)
local cwd = vim.fn.getcwd()
-- Make both paths absolute for comparison
local abs_filepath = vim.fn.fnamemodify(filepath, ":p")
local abs_cwd = vim.fn.fnamemodify(cwd, ":p")
-- Check if filepath starts with cwd
return abs_filepath:sub(1, #abs_cwd) == abs_cwd
end
function M.get_file_icon(filepath)
local filetype = Filetype.detect(filepath, {}) or "unknown"
---@type string

View File

@@ -826,6 +826,7 @@ function M.get_current_selection_diagnostics(bufnr, selection)
end
function M.uniform_path(path)
if not M.file.is_in_cwd(path) then return path end
local project_root = M.get_project_root()
local abs_path = Path:new(project_root):joinpath(path):absolute()
local relative_path = Path:new(abs_path):make_relative(project_root)