aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/fs.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2024-05-13 07:44:09 -0600
committerSteven Arcangeli <stevearc@stevearc.com>2024-05-13 07:44:38 -0600
commit4f0cdf07b5498935c34d6cfefde059a3a91584c4 (patch)
treec2eb24cf584ce0bfa947eafd80ce94a5433f458e /lua/conform/fs.lua
parentdc950e5717f1da65b1fcd986b1bbff0d6bd0e2ee (diff)
fix(windows): assertion failure when computing relative path (#400)
Diffstat (limited to 'lua/conform/fs.lua')
-rw-r--r--lua/conform/fs.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/lua/conform/fs.lua b/lua/conform/fs.lua
index 6f92e18..187bd7c 100644
--- a/lua/conform/fs.lua
+++ b/lua/conform/fs.lua
@@ -73,7 +73,15 @@ M.relative_path = function(source, target)
while not M.is_subpath(source, target) do
table.insert(path, "..")
local new_source = vim.fs.dirname(source)
- assert(source ~= new_source)
+
+ -- If source is a root directory, we can't go up further so there is no relative path to the
+ -- target. This should only happen on Windows, which prohibits relative paths between drives.
+ if source == new_source then
+ local log = require("conform.log")
+ log.warn("Could not find relative path from %s to %s", source, target)
+ return target
+ end
+
source = new_source
end